Skip to content

Commit 6c8a242

Browse files
committed
Compute outer.path in lambdaLift at correct phase.
LambdaLift needs to compute outer.path at the phase in which the results are constructed, i.e. phase lambdaLift.next. Or else we get an error in outer.path for lost fo files, including pos/Fileish.scala as a minimized test case. Previously outer as computed at phase lambdaLift. The reason for this is that lambdaLift name mangles inner classes, which causes outer acessors to be not found. We now correct for the problem in outer.path itself, by calling outerAccessor only at a safe phase.
1 parent 5cb4ecb commit 6c8a242

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ object Contexts {
231231
final def withPhase(phase: Phase): Context =
232232
withPhase(phase.id)
233233

234+
final def withPhaseNoLater(phase: Phase) =
235+
if (ctx.phase.id > phase.id) withPhase(phase) else ctx
236+
234237
/** If -Ydebug is on, the top of the stack trace where this context
235238
* was created, otherwise `null`.
236239
*/

src/dotty/tools/dotc/transform/ExplicitOuter.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,10 @@ object ExplicitOuter {
299299
def path(toCls: Symbol): Tree = try {
300300
def loop(tree: Tree): Tree = {
301301
val treeCls = tree.tpe.widen.classSymbol
302-
ctx.log(i"outer to $toCls of $tree: ${tree.tpe}, looking for ${outerAccName(treeCls.asClass)}")
302+
val outerAccessorCtx = ctx.withPhaseNoLater(ctx.lambdaLiftPhase) // lambdalift mangles local class names, which means we cannot reliably find outer acessors anymore
303+
ctx.log(i"outer to $toCls of $tree: ${tree.tpe}, looking for ${outerAccName(treeCls.asClass)(outerAccessorCtx)} in $treeCls")
303304
if (treeCls == toCls) tree
304-
else loop(tree select outerAccessor(treeCls.asClass))
305+
else loop(tree select outerAccessor(treeCls.asClass)(outerAccessorCtx))
305306
}
306307
ctx.log(i"computing outerpath to $toCls from ${ctx.outersIterator.map(_.owner).toList}")
307308
loop(This(ctx.owner.enclosingClass.asClass))

src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
9494
* than the previous value of `liftedowner(sym)`.
9595
*/
9696
def narrowLiftedOwner(sym: Symbol, owner: Symbol)(implicit ctx: Context) = {
97-
if (sym.owner.isTerm &&
97+
if (sym.maybeOwner.isTerm &&
9898
owner.isProperlyContainedIn(liftedOwner(sym)) &&
9999
owner != sym) {
100100
ctx.log(i"narrow lifted $sym to $owner")
@@ -366,7 +366,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
366366
val clazz = sym.enclosingClass
367367
val qual =
368368
if (clazz.isStaticOwner) singleton(clazz.thisType)
369-
else outer(ctx.withPhase(thisTransform)).path(clazz)
369+
else outer.path(clazz)
370370
transformFollowingDeep(qual.select(sym))
371371
}
372372

0 commit comments

Comments
 (0)