aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/TreeChecker.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-09-06 11:35:07 +0200
committerMartin Odersky <odersky@gmail.com>2014-09-06 11:36:35 +0200
commitb58b90683652e1b6e2c32412f0a03ba614b61b33 (patch)
treeb86490f67c73d5d91bcc54f691469812f6b88a73 /src/dotty/tools/dotc/transform/TreeChecker.scala
parente1040935cbcc1d767933c38a141372538ef63ac2 (diff)
downloaddotty-b58b90683652e1b6e2c32412f0a03ba614b61b33.tar.gz
dotty-b58b90683652e1b6e2c32412f0a03ba614b61b33.tar.bz2
dotty-b58b90683652e1b6e2c32412f0a03ba614b61b33.zip
Generalize phase postcondition checking.
Have a general way how a phase can establish a postcondition which will be checked each time a later phase is tree-checked. Moves erasure constraints from TreeChecker to Erasure's post condition.
Diffstat (limited to 'src/dotty/tools/dotc/transform/TreeChecker.scala')
-rw-r--r--src/dotty/tools/dotc/transform/TreeChecker.scala39
1 files changed, 6 insertions, 33 deletions
diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala
index 5847796b3..39c5ce8b6 100644
--- a/src/dotty/tools/dotc/transform/TreeChecker.scala
+++ b/src/dotty/tools/dotc/transform/TreeChecker.scala
@@ -13,6 +13,7 @@ import core.Constants._
import core.StdNames._
import core.Decorators._
import core.TypeErasure.isErasedType
+import core.Phases.Phase
import typer._
import typer.ErrorReporting._
import reporting.ThrowingReporter
@@ -34,14 +35,15 @@ import java.lang.AssertionError
class TreeChecker {
import ast.tpd._
- def check(ctx: Context) = {
+ def check(phasesToRun: Seq[Phase], ctx: Context) = {
println(s"checking ${ctx.compilationUnit} after phase ${ctx.phase.prev}")
val checkingCtx = ctx.fresh
.setTyperState(ctx.typerState.withReporter(new ThrowingReporter(ctx.typerState.reporter)))
- Checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
+ val checker = new Checker(phasesToRun.takeWhile(_ ne ctx.phase) :+ ctx.phase)
+ checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
}
- object Checker extends ReTyper {
+ class Checker(phasesToCheck: Seq[Phase]) extends ReTyper {
override def typed(tree: untpd.Tree, pt: Type)(implicit ctx: Context) = {
val res = tree match {
case _: untpd.UnApply =>
@@ -67,15 +69,7 @@ class TreeChecker {
assert(isSubType(tree1.tpe, tree.typeOpt), divergenceMsg(tree1.tpe, tree.typeOpt))
tree1
}
- if (ctx.erasedTypes) {
- assertErased(res)
- res match {
- case res: This =>
- assert(!ExplicitOuter.referencesOuter(ctx.owner.enclosingClass, res),
- i"Reference to $res from ${ctx.owner.showLocated}")
- case _ =>
- }
- }
+ phasesToCheck.foreach(_.checkPostCondition(res))
res
}
@@ -126,27 +120,6 @@ class TreeChecker {
tree
}
}
-
- def assertErased(tp: Type, tree: Tree = EmptyTree)(implicit ctx: Context): Unit =
- assert(isErasedType(tp), i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree / ${tree.getClass} is illegal after erasure, phase = ${ctx.phase}")
-
- /** Assert that tree type and its widened underlying type are erased.
- * Also assert that term refs have fixed symbols (so we are sure
- * they need not be reloaded using member; this would likely fail as signatures
- * may change after erasure).
- */
- def assertErased(tree: Tree)(implicit ctx: Context): Unit = {
- assertErased(tree.typeOpt, tree)
- if (!(tree.symbol == defn.Any_isInstanceOf || tree.symbol == defn.Any_asInstanceOf))
- assertErased(tree.typeOpt.widen, tree)
- if (ctx.mode.isExpr)
- tree.tpe match {
- case ref: TermRef =>
- assert(ref.denot.isInstanceOf[SymDenotation],
- i"non-sym type $ref of class ${ref.getClass} with denot of class ${ref.denot.getClass} of $tree")
- case _ =>
- }
- }
}
object TreeChecker extends TreeChecker \ No newline at end of file