From 35bf9148b6054c3651d597f90b7b721845e8734a Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Mon, 3 Nov 2014 14:42:55 +0100 Subject: Allow checking that trees and their defined symbols have modifiers in sync. --- src/dotty/tools/dotc/config/ScalaSettings.scala | 1 + src/dotty/tools/dotc/transform/TreeChecker.scala | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index abde6cb53..05b936136 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -99,6 +99,7 @@ class ScalaSettings extends Settings.SettingGroup { val Yhelp = BooleanSetting("-Y", "Print a synopsis of private options.") val browse = PhasesSetting("-Ybrowse", "Browse the abstract syntax tree after") val Ycheck = PhasesSetting("-Ycheck", "Check the tree at the end of") + val YcheckMods = BooleanSetting("-Ycheck-mods", "Check that symbols and their defining trees have modifiers in sync") val YcheckTypedTrees = BooleanSetting("-YcheckTypedTrees", "Check all constructured typed trees for type correctness") val Yshow = PhasesSetting("-Yshow", "(Requires -Xshow-class or -Xshow-object) Show after") val Xcloselim = BooleanSetting("-Yclosure-elim", "Perform closure elimination.") diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala index baaadb53f..39f4bb067 100644 --- a/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -76,12 +76,23 @@ class TreeChecker { everDefinedSyms.get(sym) match { case Some(t) => if(t ne tree) - ctx.warning(i"symbol ${tree.symbol} is defined at least twice in different parts of AST") + ctx.warning(i"symbol ${sym} is defined at least twice in different parts of AST") // should become an error case None => everDefinedSyms(sym) = tree } - assert(!nowDefinedSyms.contains(tree.symbol), i"doubly defined symbol: ${tree.symbol}in $tree") + assert(!nowDefinedSyms.contains(sym), i"doubly defined symbol: ${sym} in $tree") + + if(ctx.settings.YcheckMods.value) { + tree match { + case t: MemberDef => + if (t.name ne sym.name) ctx.warning(s"symbol ${sym.fullName} name doesn't correspond to AST: ${t}") + if (sym.flags != t.mods.flags) ctx.warning(s"symbol ${sym.fullName} flags ${sym.flags} doesn't match AST definition flags ${t.mods.flags}") + // todo: compare trees inside annotations + case _ => + } + } + nowDefinedSyms += tree.symbol //println(i"defined: ${tree.symbol}") val res = op -- cgit v1.2.3