@@ -30,38 +30,41 @@ class HealType(pos: SrcPos)(using Context) extends TypeMap {
3030 */
3131 def apply (tp : Type ): Type =
3232 tp match
33- case tp : TypeRef =>
34- healTypeRef(tp)
35- case tp @ TermRef (NoPrefix , _) if ! tp.symbol.isStatic && level > levelOf(tp.symbol) =>
36- levelError(tp.symbol, tp, pos)
33+ case tp @ TypeRef (NoPrefix , _) if tp.typeSymbol.hasAnnotation(defn.QuotedRuntime_SplicedTypeAnnot ) =>
34+ tp
35+ case tp @ TypeRef (prefix : TermRef , _) if tp.symbol.isTypeSplice && level > 0 =>
36+ checkNotWildcardSplice(tp)
37+ getQuoteTypeTags.getTagRef(prefix)
38+ case tp @ TypeRef (_ : NamedType | _ : ThisType | NoPrefix , _) =>
39+ if levelInconsistentRootOfPath(tp).exists then
40+ val tp1 = tp.dealias
41+ if tp1 != tp then apply(tp1)
42+ else tryHeal(tp.symbol, tp, pos)
43+ else
44+ tp
45+ case tp : TermRef =>
46+ val inconsistentRoot = levelInconsistentRootOfPath(tp)
47+ if inconsistentRoot.exists then levelError(inconsistentRoot, tp, pos)
48+ else tp
3749 case tp : AnnotatedType =>
3850 derivedAnnotatedType(tp, apply(tp.parent), tp.annot)
3951 case _ =>
4052 mapOver(tp)
4153
42- private def healTypeRef (tp : TypeRef ): Type =
43- tp.prefix match
44- case prefix : TermRef if tp.symbol.isTypeSplice =>
45- checkNotWildcardSplice(tp)
46- if level == 0 then tp else getQuoteTypeTags.getTagRef(prefix)
47- case prefix : TermRef if ! prefix.symbol.isStatic && level > levelOf(prefix.symbol) =>
48- dealiasAndTryHeal(prefix.symbol, tp, pos)
49- case NoPrefix if level > levelOf(tp.symbol) && ! tp.typeSymbol.hasAnnotation(defn.QuotedRuntime_SplicedTypeAnnot ) =>
50- dealiasAndTryHeal(tp.symbol, tp, pos)
51- case prefix : ThisType if level > levelOf(prefix.cls) && ! tp.symbol.isStatic =>
52- dealiasAndTryHeal(tp.symbol, tp, pos)
53- case _ =>
54- mapOver(tp)
55-
5654 private def checkNotWildcardSplice (splice : TypeRef ): Unit =
5755 splice.prefix.termSymbol.info.argInfos match
5856 case (tb : TypeBounds ) :: _ => report.error(em " Cannot splice $splice because it is a wildcard type " , pos)
5957 case _ =>
6058
61- private def dealiasAndTryHeal (sym : Symbol , tp : TypeRef , pos : SrcPos ): Type =
62- val tp1 = tp.dealias
63- if tp1 != tp then apply(tp1)
64- else tryHeal(tp.symbol, tp, pos)
59+ /** Return the root of this path if it is a variable defined in a previous level.
60+ * If the path is consistent, return NoSymbol.
61+ */
62+ private def levelInconsistentRootOfPath (tp : Type )(using Context ): Symbol =
63+ tp match
64+ case tp @ NamedType (NoPrefix , _) if level > levelOf(tp.symbol) => tp.symbol
65+ case tp : NamedType if ! tp.symbol.isStatic => levelInconsistentRootOfPath(tp.prefix)
66+ case tp : ThisType if level > levelOf(tp.cls) => tp.cls
67+ case _ => NoSymbol
6568
6669 /** Try to heal reference to type `T` used in a higher level than its definition.
6770 * Returns a reference to a type tag generated by `QuoteTypeTags` that contains a
0 commit comments