Skip to content

Commit a3d351a

Browse files
committed
Fix #7048: PCP heal static path dependent types
1 parent 082edca commit a3d351a

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,21 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
153153
/** Is a reference to a class but not `this.type` */
154154
def isClassRef = sym.isClass && !tp.isInstanceOf[ThisType]
155155

156-
if (!sym.exists || levelOK(sym))
156+
/** Is this a static path or a type porjection with a static prefix */
157+
def isStaticPathOK(tp1: Type): Boolean =
158+
tp1.stripTypeVar match
159+
case tp1: TypeRef => tp1.symbol.is(Package) || isStaticPathOK(tp1.prefix)
160+
case tp1: TermRef =>
161+
def isStaticTermPathOK(sym: Symbol): Boolean =
162+
(sym.is(Module) && sym.isStatic) ||
163+
(sym.isStableMember && isStaticTermPathOK(sym.owner))
164+
isStaticTermPathOK(tp1.symbol)
165+
case tp1: ThisType => tp1.cls.isStaticOwner
166+
case tp1: AppliedType => isStaticPathOK(tp1.tycon)
167+
case tp1: SkolemType => isStaticPathOK(tp1.info)
168+
case _ => false
169+
170+
if (!sym.exists || levelOK(sym) || isStaticPathOK(tp))
157171
None
158172
else if (!sym.isStaticOwner && !isClassRef)
159173
tryHeal(sym, tp, pos)
@@ -180,7 +194,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
180194
sym.isClass // reference to this in inline methods
181195
)
182196
case None =>
183-
!sym.is(Param) || levelOK(sym.owner)
197+
sym.is(Package) || sym.owner.isStaticOwner || levelOK(sym.owner)
184198
}
185199

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

0 commit comments

Comments
 (0)