|
1 | | -package dotty.tools.dotc |
| 1 | +package dotty.tools |
| 2 | +package dotc |
2 | 3 | package transform |
3 | 4 |
|
4 | 5 | import MegaPhase._ |
@@ -178,7 +179,7 @@ object ExplicitOuter { |
178 | 179 |
|
179 | 180 | /** A new param accessor for the outer field in class `cls` */ |
180 | 181 | private def newOuterParamAccessor(cls: ClassSymbol)(implicit ctx: Context) = |
181 | | - newOuterSym(cls, cls, nme.OUTER, Private | ParamAccessor) |
| 182 | + newOuterSym(cls, cls, nme.OUTER, Private | Local | ParamAccessor) |
182 | 183 |
|
183 | 184 | /** A new outer accessor for class `cls` which is a member of `owner` */ |
184 | 185 | private def newOuterAccessor(owner: ClassSymbol, cls: ClassSymbol)(implicit ctx: Context) = { |
@@ -322,6 +323,9 @@ object ExplicitOuter { |
322 | 323 | tpe |
323 | 324 | } |
324 | 325 |
|
| 326 | + def (sym: Symbol).isOuterParamAccessor(using Context): Boolean = |
| 327 | + sym.is(ParamAccessor) && sym.name == nme.OUTER |
| 328 | + |
325 | 329 | def outer(implicit ctx: Context): OuterOps = new OuterOps(ctx) |
326 | 330 |
|
327 | 331 | /** The operations in this class |
@@ -386,26 +390,28 @@ object ExplicitOuter { |
386 | 390 | */ |
387 | 391 | def path(start: Tree = This(ctx.owner.lexicallyEnclosingClass.asClass), |
388 | 392 | toCls: Symbol = NoSymbol, |
389 | | - count: Int = -1): Tree = try { |
390 | | - @tailrec def loop(tree: Tree, count: Int): Tree = { |
391 | | - val treeCls = tree.tpe.widen.classSymbol |
392 | | - val outerAccessorCtx = ctx.withPhaseNoLater(ctx.lambdaLiftPhase) // lambdalift mangles local class names, which means we cannot reliably find outer acessors anymore |
393 | | - ctx.log(i"outer to $toCls of $tree: ${tree.tpe}, looking for ${outerAccName(treeCls.asClass)(outerAccessorCtx)} in $treeCls") |
394 | | - if (count == 0 || count < 0 && treeCls == toCls) tree |
395 | | - else { |
396 | | - val acc = outerAccessor(treeCls.asClass)(outerAccessorCtx) |
397 | | - assert(acc.exists, |
398 | | - i"failure to construct path from ${ctx.owner.ownersIterator.toList}%/% to `this` of ${toCls.showLocated};\n${treeCls.showLocated} does not have an outer accessor") |
399 | | - loop(tree.select(acc).ensureApplied, count - 1) |
400 | | - } |
401 | | - } |
402 | | - ctx.log(i"computing outerpath to $toCls from ${ctx.outersIterator.map(_.owner).toList}") |
403 | | - loop(start, count) |
404 | | - } |
405 | | - catch { |
406 | | - case ex: ClassCastException => |
| 393 | + count: Int = -1): Tree = |
| 394 | + try |
| 395 | + @tailrec def loop(tree: Tree, count: Int): Tree = |
| 396 | + val treeCls = tree.tpe.widen.classSymbol |
| 397 | + val outerAccessorCtx = ctx.withPhaseNoLater(ctx.lambdaLiftPhase) // lambdalift mangles local class names, which means we cannot reliably find outer acessors anymore |
| 398 | + ctx.log(i"outer to $toCls of $tree: ${tree.tpe}, looking for ${outerAccName(treeCls.asClass)(outerAccessorCtx)} in $treeCls") |
| 399 | + if (count == 0 || count < 0 && treeCls == toCls) tree |
| 400 | + else |
| 401 | + val enclClass = ctx.owner.lexicallyEnclosingClass.asClass |
| 402 | + val outerAcc = tree match |
| 403 | + case tree: This if tree.symbol == enclClass && !enclClass.is(Trait) => |
| 404 | + outerParamAccessor(enclClass)(using outerAccessorCtx) |
| 405 | + case _ => |
| 406 | + outerAccessor(treeCls.asClass)(using outerAccessorCtx) |
| 407 | + assert(outerAcc.exists, |
| 408 | + i"failure to construct path from ${ctx.owner.ownersIterator.toList}%/% to `this` of ${toCls.showLocated};\n${treeCls.showLocated} does not have an outer accessor") |
| 409 | + loop(tree.select(outerAcc).ensureApplied, count - 1) |
| 410 | + |
| 411 | + ctx.log(i"computing outerpath to $toCls from ${ctx.outersIterator.map(_.owner).toList}") |
| 412 | + loop(start, count) |
| 413 | + catch case ex: ClassCastException => |
407 | 414 | throw new ClassCastException(i"no path exists from ${ctx.owner.enclosingClass} to $toCls") |
408 | | - } |
409 | 415 |
|
410 | 416 | /** The outer parameter definition of a constructor if it needs one */ |
411 | 417 | def paramDefs(constr: Symbol): List[ValDef] = |
|
0 commit comments