From d78885ff06bea4840cdf9bee61dd3698fcff820a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 19 Apr 2014 19:48:57 +0200 Subject: isAfterTyper test Add test whether we are after typer. Use it to assert that eta expansion and implicit search do not happen after typer. --- src/dotty/tools/dotc/core/Phases.scala | 6 +++++- src/dotty/tools/dotc/typer/EtaExpansion.scala | 1 + src/dotty/tools/dotc/typer/Implicits.scala | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/dotty') diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala index f76b83db6..251cd3876 100644 --- a/src/dotty/tools/dotc/core/Phases.scala +++ b/src/dotty/tools/dotc/core/Phases.scala @@ -36,6 +36,8 @@ trait Phases { def atPhaseNotLaterThanTyper[T](op: Context => T): T = atPhaseNotLaterThan(base.typerPhase)(op) + + def isAfterTyper: Boolean = base.isAfterTyper(phase) } object Phases { @@ -177,9 +179,11 @@ object Phases { def refchecksPhase = refChecksCache.phase def erasurePhase = erasureCache.phase def flattenPhase = flattenCache.phase + + def isAfterTyper(phase: Phase): Boolean = phase.id > typerPhase.id } - final val typerName = "typer" + final val typerName = "frontend" final val refChecksName = "refchecks" final val erasureName = "erasure" final val flattenName = "flatten" diff --git a/src/dotty/tools/dotc/typer/EtaExpansion.scala b/src/dotty/tools/dotc/typer/EtaExpansion.scala index 099dd943a..110dc6152 100644 --- a/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -116,6 +116,7 @@ object EtaExpansion { */ def etaExpand(tree: Tree, mt: MethodType, xarity: Int)(implicit ctx: Context): untpd.Tree = { import untpd._ + assert(!ctx.isAfterTyper) val defs = new mutable.ListBuffer[tpd.Tree] val lifted: Tree = TypedSplice(liftApp(defs, tree)) val paramTypes: List[Tree] = diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index 93876651a..4767e6dd3 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -400,6 +400,7 @@ trait Implicits { self: Typer => * !!! todo: catch potential cycles */ def inferImplicit(pt: Type, argument: Tree, pos: Position)(implicit ctx: Context): SearchResult = track("inferImplicit") { + assert(!ctx.isAfterTyper) ctx.traceIndented(s"search implicit ${pt.show}, arg = ${argument.show}: ${argument.tpe.show}", implicits, show = true) { assert(!pt.isInstanceOf[ExprType]) val isearch = @@ -472,7 +473,7 @@ trait Implicits { self: Typer => shadowedImplicit(ref, methPart(shadowing).tpe) } else - SearchSuccess(generated, ref, ctx.typerState) + SearchSuccess(generated1, ref, ctx.typerState) }} /** Given a list of implicit references, produce a list of all implicit search successes, -- cgit v1.2.3