Skip to content

Commit bb73f5f

Browse files
Backport "Fix handling of AppliedType aliases in outerPrefix" to LTS (#21082)
Backports #20190 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents e6592d9 + 81c7ff3 commit bb73f5f

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

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

+5-18
Original file line numberDiff line numberDiff line change
@@ -343,25 +343,12 @@ object ExplicitOuter {
343343
private final val HoistableFlags = Method | Lazy | Module
344344

345345
/** The outer prefix implied by type `tpe` */
346-
private def outerPrefix(tpe: Type)(using Context): Type = tpe match {
347-
case tpe: TypeRef =>
348-
tpe.symbol match {
349-
case cls: ClassSymbol =>
350-
if (tpe.prefix eq NoPrefix) cls.owner.enclosingClass.thisType
351-
else tpe.prefix
352-
case _ =>
353-
// Need to be careful to dealias before erasure, otherwise we lose prefixes.
354-
atPhaseNoLater(erasurePhase)(outerPrefix(tpe.underlying))
355-
// underlying is fine here and below since we are calling this after erasure.
356-
// However, there is some weird stuff going on with parboiled2 where an
357-
// AppliedType with a type alias as constructor is fed to outerPrefix.
358-
// For some other unknown reason this works with underlying but not with superType.
359-
// I was not able to minimize the problem and parboiled2 spits out way too much
360-
// macro generated code to be able to pinpoint the root problem.
361-
}
346+
private def outerPrefix(tpe: Type)(using Context): Type = tpe match
347+
case tpe: TypeRef if tpe.symbol.isClass =>
348+
if tpe.prefix eq NoPrefix then tpe.symbol.owner.enclosingClass.thisType
349+
else tpe.prefix
362350
case tpe: TypeProxy =>
363-
outerPrefix(tpe.underlying)
364-
}
351+
atPhaseNoLater(erasurePhase)(outerPrefix(tpe.superType))
365352

366353
/** It's possible (i1755.scala gives an example) that the type
367354
* given by outerPrefix contains a This-reference to a module outside

tests/pos/i20184.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Outer:
2+
def Test =
3+
object Inner:
4+
var x: Int = 2
5+
class Rgb():
6+
def f = x
7+
8+
type Id[X] = X
9+
type TRgb = Id[Inner.Rgb]
10+
11+
val ok = new Inner.Rgb()
12+
val crash = new Id[Inner.Rgb]

0 commit comments

Comments
 (0)