Skip to content

Commit 5f695f5

Browse files
committed
Fix #7048: PCP heal path dependent types
1 parent 754fa51 commit 5f695f5

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,26 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
119119
// Replace it with a properly encoded type splice. This is the normal for expected for type splices.
120120
tp.prefix.select(tpnme.splice)
121121
case tp: NamedType =>
122-
checkSymLevel(tp.symbol, tp, pos) match {
123-
case Some(tpRef) => tpRef.tpe
124-
case _ =>
125-
if (tp.symbol.is(Param)) tp
126-
else mapOver(tp)
122+
/** Is this a static path or a type porjection with a static prefix */
123+
def isStaticPathOK(tp1: Type): Boolean = tp1 match {
124+
case tp1: TypeRef => tp1.symbol.is(Package) || isStaticPathOK(tp1.prefix)
125+
case tp1: TermRef => tp1.symbol.isStaticOwner || isStaticPathOK(tp1.prefix)
126+
case tp1: ThisType => tp1.tref.symbol.is(Package) || tp1.tref.symbol.is(Module)
127+
case tp1: AppliedType => isStaticPathOK(tp1.tycon)
128+
case _: SkolemType => true
129+
case _ => false
127130
}
131+
132+
if (isStaticPathOK(tp))
133+
if (tp.symbol.is(Param)) tp
134+
else mapOver(tp)
135+
else
136+
checkSymLevel(tp.symbol, tp, pos) match {
137+
case Some(tpRef) => tpRef.tpe
138+
case _ =>
139+
if (tp.symbol.is(Param)) tp
140+
else mapOver(tp)
141+
}
128142
case tp: ThisType =>
129143
assert(checkSymLevel(tp.cls, tp, pos).isEmpty)
130144
mapOver(tp)
@@ -171,7 +185,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
171185
sym.isClass // reference to this in inline methods
172186
)
173187
case None =>
174-
!sym.is(Param) || levelOK(sym.owner)
188+
sym.is(Package)|| sym.owner.isStaticOwner || levelOK(sym.owner)
175189
}
176190

177191
/** Try to heal phase-inconsistent reference to type `T` using a local type definition.
File renamed without changes.

0 commit comments

Comments
 (0)