diff options
-rw-r--r-- | src/dotty/tools/dotc/transform/TreeChecker.scala | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala index f52c5bc1c..f39dd505a 100644 --- a/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -14,8 +14,10 @@ import core.Decorators._ import core.transform.Erasure.isUnboundedGeneric import typer._ import typer.ErrorReporting._ +import reporting.ThrowingReporter 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. @@ -25,36 +27,49 @@ class TreeChecker { def check(ctx: Context) = { println(s"checking ${ctx.compilationUnit} after phase ${ctx.phase.prev}") - Checker.typedExpr(ctx.compilationUnit.tpdTree)(ctx) + val checkingCtx = ctx.fresh + .setTyperState(ctx.typerState.withReporter(new ThrowingReporter(ctx.typerState.reporter))) + Checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx) } object Checker extends ReTyper { - override def typed(tree: untpd.Tree, pt: Type)(implicit ctx: Context) = - if (tree.isEmpty) tree.asInstanceOf[Tree] - else { - assert(tree.hasType, tree.show) - val tree1 = super.typed(tree, pt) - def sameType(tp1: Type, tp2: Type) = - (tp1 eq tp2) || // accept NoType / NoType - (tp1 =:= tp2) - def divergenceMsg = - s"""Types differ - |Original type : ${tree.typeOpt.show} - |After checking: ${tree1.tpe.show} - |Original tree : ${tree.show} - |After checking: ${tree1.show} - """.stripMargin - assert(sameType(tree1.tpe, tree.typeOpt), divergenceMsg) - tree1 - } + override def typed(tree: untpd.Tree, pt: Type)(implicit ctx: Context) = try { + tree match { + case _: untpd.UnApply => + // can't recheck patterns + tree.asInstanceOf[tpd.Tree] + case _: untpd.TypedSplice | _: untpd.Thicket | _: EmptyValDef[_] => + super.typed(tree) + case _ if tree.isType => + promote(tree) + case _ => + val tree1 = super.typed(tree, pt) + def sameType(tp1: Type, tp2: Type) = + (tp1 eq tp2) || // accept NoType / NoType + (tp1 =:= tp2) + def divergenceMsg = + s"""Types differ + |Original type : ${tree.typeOpt.show} + |After checking: ${tree1.tpe.show} + |Original tree : ${tree.show} + |After checking: ${tree1.show} + """.stripMargin + assert(sameType(tree1.tpe, tree.typeOpt), divergenceMsg) + tree1 + } + } catch { + case ex: Throwable => + println(i"exception while checking $tree of class ${tree.getClass} # ${tree.uniqueId}") + throw ex + } override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = { - assert(tree.isTerm, tree.show) + assert(tree.isTerm || ctx.phase.prev.id <= ctx.typerPhase.id, tree.show + " at " + ctx.phase) super.typedIdent(tree, pt) } override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = { - assert(tree.isTerm, tree.show) + assert(tree.isTerm || ctx.phase.prev.id <= ctx.typerPhase.id, tree.show + " at " + ctx.phase) super.typedSelect(tree, pt) } } |