aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/TreeChecker.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-08-24 18:04:22 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-24 18:09:01 +0200
commitaa7a0399ad5424dd5292f2f1941c7293c16d6b79 (patch)
treefcc3efccc01f6d5160774c0b3998481f2d492500 /src/dotty/tools/dotc/transform/TreeChecker.scala
parent70abd73e9306eca3ec4de1d98b877e4fafe66ad0 (diff)
downloaddotty-aa7a0399ad5424dd5292f2f1941c7293c16d6b79.tar.gz
dotty-aa7a0399ad5424dd5292f2f1941c7293c16d6b79.tar.bz2
dotty-aa7a0399ad5424dd5292f2f1941c7293c16d6b79.zip
Check that idents don't assume magic.
In TreeChecker, make sure that every identifier has a type with an elidable prefix. This excludes identifiers pointing to members of random prefixes without making the prefix explicit in the tree as part of a Select node.
Diffstat (limited to 'src/dotty/tools/dotc/transform/TreeChecker.scala')
-rw-r--r--src/dotty/tools/dotc/transform/TreeChecker.scala16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala
index 3c5c9a0c3..87254a217 100644
--- a/src/dotty/tools/dotc/transform/TreeChecker.scala
+++ b/src/dotty/tools/dotc/transform/TreeChecker.scala
@@ -19,8 +19,15 @@ import ast.Trees._
import ast.{tpd, untpd}
import java.lang.AssertionError
-/** This transform eliminates patterns. Right now it's a dummy.
- * Awaiting the real pattern matcher.
+/** Run by -Ycheck option after a given phase, this class retypes all syntax trees
+ * and verifies that the type of each tree node so obtained conforms to the type found in the tree node.
+ * It also performs the following checks:
+ *
+ * - The owner of each definition is the same as the owner of the current typing context.
+ * - Ident nodes do not refer to a denotation that would need a select to be accessible
+ * (see tpd.needsSelect).
+ * - After typer, identifiers and select nodes refer to terms only (all types should be
+ * represented as TypeTrees then).
*/
class TreeChecker {
import ast.tpd._
@@ -65,12 +72,13 @@ class TreeChecker {
}
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = {
- assert(tree.isTerm || ctx.phase.prev.id <= ctx.typerPhase.id, tree.show + " at " + ctx.phase)
+ assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
+ assert(!needsSelect(tree.tpe), i"bad type ${tree.tpe} for $tree")
super.typedIdent(tree, pt)
}
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
- assert(tree.isTerm || ctx.phase.prev.id <= ctx.typerPhase.id, tree.show + " at " + ctx.phase)
+ assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
super.typedSelect(tree, pt)
}