From 44d9da14637538f5c908e786ddc82c6504b44084 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 15 Apr 2024 15:46:52 +0200 Subject: [PATCH] Streamline outerPrefix --- .../tools/dotc/transform/ExplicitOuter.scala | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index b851db26f5c8..15dfda845389 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -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