Skip to content

Commit fc99492

Browse files
committed
Fix #7048: PCP heal static path dependent types
1 parent 4719e7b commit fc99492

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
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.

tests/pending/pos/i7048.scala renamed to tests/pos/i7048.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait IsExpr[T] {
77

88
def f(x: Any): String = x.toString
99

10-
def g[T](given e: IsExpr[T], tu: Type[e.Underlying]): (given QuoteContext) => Expr[String] = {
10+
def g[T](given e: IsExpr[T], tu: TypeTag[e.Underlying]): (given QuoteContext) => Expr[String] = {
1111
val underlying: Expr[e.Underlying] = e.expr
1212
'{f($underlying)}
1313
}

tests/pending/run-macros/i7048/Lib_1.scala renamed to tests/run-macros/i7048/Lib_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ given [U] : IsExpr[Expr[U]] = new IsExpr[Expr[U]] {
1212

1313
def f(x: Any): String = x.toString
1414

15-
def g[T](x: T)(given e: IsExpr[T], tu: Type[e.Underlying]): (given QuoteContext) => Expr[String] = {
15+
def g[T](x: T)(given e: IsExpr[T], tu: TypeTag[e.Underlying]): (given QuoteContext) => Expr[String] = {
1616
val underlying: Expr[e.Underlying] = e.toExpr(x)
1717
'{f($underlying)}
1818
}

0 commit comments

Comments
 (0)