@@ -209,7 +209,7 @@ object ExplicitOuter {
209
209
private def hasOuterParam (cls : ClassSymbol )(implicit ctx : Context ): Boolean =
210
210
! cls.is(Trait ) && needsOuterIfReferenced(cls) && outerAccessor(cls).exists
211
211
212
- /** Tree references a an outer class of `cls` which is not a static owner.
212
+ /** Tree references an outer class of `cls` which is not a static owner.
213
213
*/
214
214
def referencesOuter (cls : Symbol , tree : Tree )(implicit ctx : Context ): Boolean = {
215
215
def isOuter (sym : Symbol ) =
@@ -231,7 +231,12 @@ object ExplicitOuter {
231
231
case _ => false
232
232
}
233
233
case nw : New =>
234
- isOuter(nw.tpe.classSymbol.owner.enclosingClass)
234
+ val newCls = nw.tpe.classSymbol
235
+ isOuter(newCls.owner.enclosingClass) ||
236
+ newCls.owner.isTerm && cls.isProperlyContainedIn(newCls)
237
+ // newCls might get proxies for free variables. If current class is
238
+ // properly contained in newCls, it needs an outer path to newCls access the
239
+ // proxies and forward them to the new instance.
235
240
case _ =>
236
241
false
237
242
}
@@ -308,7 +313,7 @@ object ExplicitOuter {
308
313
/** The path of outer accessors that references `toCls.this` starting from
309
314
* the context owner's this node.
310
315
*/
311
- def path (toCls : Symbol ): Tree = try {
316
+ def path (toCls : Symbol , start : Tree = This (ctx.owner.enclosingClass.asClass) ): Tree = try {
312
317
def loop (tree : Tree ): Tree = {
313
318
val treeCls = tree.tpe.widen.classSymbol
314
319
val outerAccessorCtx = ctx.withPhaseNoLater(ctx.lambdaLiftPhase) // lambdalift mangles local class names, which means we cannot reliably find outer acessors anymore
@@ -317,7 +322,7 @@ object ExplicitOuter {
317
322
else loop(tree.select(outerAccessor(treeCls.asClass)(outerAccessorCtx)).ensureApplied)
318
323
}
319
324
ctx.log(i " computing outerpath to $toCls from ${ctx.outersIterator.map(_.owner).toList}" )
320
- loop(This (ctx.owner.enclosingClass.asClass) )
325
+ loop(start )
321
326
} catch {
322
327
case ex : ClassCastException =>
323
328
throw new ClassCastException (i " no path exists from ${ctx.owner.enclosingClass} to $toCls" )
0 commit comments