From dbb0279a788d606892b123aa3baaa94614d676ff Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 2 Dec 2016 08:53:04 +0100 Subject: Fix-1756: Use lexically enclosing class as start of outer path. We confused the enclosing class (which skips the current class in super call contexts) and the lexically enclosing class in three locations that all had to do with the start of an outer path. --- compiler/src/dotty/tools/dotc/transform/Erasure.scala | 4 ++-- compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'compiler/src') diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 069176111..0d0339ece 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -82,7 +82,7 @@ class Erasure extends Phase with DenotTransformer { thisTransformer => assertErased(tree) tree match { case res: tpd.This => - assert(!ExplicitOuter.referencesOuter(ctx.owner.enclosingClass, res), + assert(!ExplicitOuter.referencesOuter(ctx.owner.lexicallyEnclosingClass, res), i"Reference to $res from ${ctx.owner.showLocated}") case ret: tpd.Return => // checked only after erasure, as checking before erasure is complicated @@ -389,7 +389,7 @@ object Erasure extends TypeTestsCasts{ } override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = - if (tree.symbol == ctx.owner.enclosingClass || tree.symbol.isStaticOwner) promote(tree) + if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree) else { ctx.log(i"computing outer path from ${ctx.owner.ownersIterator.toList}%, % to ${tree.symbol}, encl class = ${ctx.owner.enclosingClass}") outer.path(tree.symbol) diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index 3fec47e9f..a32e1c921 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -330,7 +330,7 @@ object ExplicitOuter { /** The path of outer accessors that references `toCls.this` starting from * the context owner's this node. */ - def path(toCls: Symbol, start: Tree = This(ctx.owner.enclosingClass.asClass)): Tree = try { + def path(toCls: Symbol, start: Tree = This(ctx.owner.lexicallyEnclosingClass.asClass)): Tree = try { def loop(tree: Tree): Tree = { val treeCls = tree.tpe.widen.classSymbol val outerAccessorCtx = ctx.withPhaseNoLater(ctx.lambdaLiftPhase) // lambdalift mangles local class names, which means we cannot reliably find outer acessors anymore -- cgit v1.2.3