Skip to content

Commit

Permalink
Streamline outerPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Apr 15, 2024
1 parent ab4b12c commit 44d9da1
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -343,25 +343,12 @@ object ExplicitOuter {
private final val HoistableFlags = Method | Lazy | Module

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

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

0 comments on commit 44d9da1

Please sign in to comment.