@@ -192,11 +192,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
192192 case tp : TypeRef =>
193193 tp.prefix match
194194 case NoPrefix if level > levelOf(tp.symbol) && ! tp.typeSymbol.hasAnnotation(defn.QuotedRuntime_SplicedTypeAnnot ) =>
195- val tp1 = tp.dealias
196- if tp1 != tp then apply(tp1)
197- else tryHeal(tp.symbol, tp, pos)
195+ tryHealTypeOfType(tp.symbol, tp, pos)
198196 case prefix : ThisType if ! tp.symbol.isStatic && level > levelOf(prefix.cls) =>
199- tryHeal (tp.symbol, tp, pos)
197+ tryHealTypeOfType (tp.symbol, tp, pos)
200198 case prefix : TermRef if tp.symbol.isTypeSplice =>
201199 prefix.symbol.info.argInfos match
202200 case (tb : TypeBounds ) :: _ =>
@@ -205,7 +203,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
205203 // Heal explicit type splice in the code
206204 if level > 0 then getQuoteTypeTags.getTagRef(prefix) else tp
207205 case prefix : TermRef if ! prefix.symbol.isStatic && level > levelOf(prefix.symbol) =>
208- tryHeal (prefix.symbol, tp, pos)
206+ tryHealTypeOfType (prefix.symbol, tp, pos)
209207 case _ =>
210208 mapOver(tp)
211209 case tp @ TermRef (NoPrefix , _) if ! tp.symbol.isStatic && level > levelOf(tp.symbol) =>
@@ -217,6 +215,17 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
217215 derivedAnnotatedType(tp, apply(tp.parent), tp.annot.derivedAnnotation(newAnnotTree))
218216 case _ =>
219217 mapOver(tp)
218+
219+ /** Try to dealias or heal reference to type `T` used in a higher level than its definition.
220+ * Returns a reference to a type tag generated by `QuoteTypeTags` that contains a
221+ * reference to a type alias containing the equivalent of `${summon[quoted.Type[T]]}`.
222+ * Emits and error if `T` cannot be healed and returns `T`.
223+ */
224+ private def tryHealTypeOfType (sym : Symbol , tp : TypeRef , pos : SrcPos )(using Context ): Type = {
225+ val tp1 = tp.dealias
226+ if tp1 != tp then apply(tp1)
227+ else tryHeal(tp.symbol, tp, pos)
228+ }
220229 }
221230
222231 /** Check phase consistency of terms and heal inconsistent type references. */
0 commit comments