Skip to content

Commit c40302c

Browse files
committed
Fix #1865: Compute outer path at right phase
When computing the outer path, we need to be careful to dealias before erasure, even if the outer path is demanded during erasure. Otherwise we lose prefixes.
1 parent 39c27b6 commit c40302c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ object ExplicitOuter {
276276
if (tpe.prefix eq NoPrefix) cls.owner.enclosingClass.thisType
277277
else tpe.prefix
278278
case _ =>
279-
outerPrefix(tpe.underlying)
279+
outerPrefix(tpe.underlying(ctx.withPhaseNoLater(ctx.erasurePhase)))
280280
}
281281
case tpe: TypeProxy =>
282282
outerPrefix(tpe.underlying)
@@ -339,6 +339,7 @@ object ExplicitOuter {
339339
val cls = fun.symbol.owner.asClass
340340
def outerArg(receiver: Tree): Tree = receiver match {
341341
case New(_) | Super(_, _) =>
342+
println(i"outerarg: ${receiver.tpe} --> ${outerPrefix(receiver.tpe)} at ${ctx.phase}")
342343
singleton(fixThis(outerPrefix(receiver.tpe)))
343344
case This(_) =>
344345
ref(outerParamAccessor(cls)) // will be rewired to outer argument of secondary constructor in phase Constructors

tests/pending/pos/i1865.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class AbsCell {
2+
type T = Node
3+
class Node
4+
}
5+
6+
object Test {
7+
def test: Unit = {
8+
val cell = new AbsCell
9+
new cell.T
10+
}
11+
}
12+
13+
class AbsCell2 {
14+
type T = Node
15+
val value: T = value
16+
def set(x: T): Unit = {}
17+
class Node
18+
}
19+
object init {
20+
def main = {
21+
val cell = new AbsCell2 { val init = new Node }
22+
cell set (new cell.T)
23+
}
24+
}

0 commit comments

Comments
 (0)