@@ -37,8 +37,8 @@ import scala.annotation.constructorOnly
37
37
*
38
38
* Type healing consists in transforming a phase inconsistent type `T` into a splice of `${summon[Type[T]]}`.
39
39
*
40
- * As references to types do not necessarily have an assosiated tree it is not always possible to replace the types directly.
41
- * Instead we always generate a type alias for it and palce it at the start of the surounding quote. This also avoids duplication.
40
+ * As references to types do not necessarily have an associated tree it is not always possible to replace the types directly.
41
+ * Instead we always generate a type alias for it and place it at the start of the surrounding quote. This also avoids duplication.
42
42
* For example:
43
43
* '{
44
44
* val x: List[T] = List[T]()
@@ -118,7 +118,13 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
118
118
case Nil => body1
119
119
case tags => tpd.Block (tags, body1).withSpan(body.span)
120
120
121
- super .transformQuotation(body2, quote)
121
+ quote match {
122
+ case Apply (fn1 @ TypeApply (fn0, targs), _) =>
123
+ val targs1 = targs.map(targ => TypeTree (healTypeOfTerm(fn1.srcPos)(targ.tpe)))
124
+ cpy.Apply (quote)(cpy.TypeApply (fn1)(fn0, targs1), body2 :: Nil )
125
+ case quote : TypeApply =>
126
+ cpy.TypeApply (quote)(quote.fun, body2 :: Nil )
127
+ }
122
128
}
123
129
124
130
/** Transform splice
@@ -168,8 +174,8 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
168
174
/** If the type refers to a locally defined symbol (either directly, or in a pickled type),
169
175
* check that its staging level matches the current level.
170
176
* - Static types and term are allowed at any level.
171
- * - If a type reference is used a higher level, then it is insosistent . Will atempt to heal before failing.
172
- * - If a term reference is used a different level, then it is insosistent .
177
+ * - If a type reference is used a higher level, then it is inconsistent . Will attempt to heal before failing.
178
+ * - If a term reference is used a different level, then it is inconsistent .
173
179
*
174
180
* If `T` is a reference to a type at the wrong level, try to heal it by replacing it with
175
181
* a type tag of type `quoted.Type[T]`.
@@ -207,7 +213,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
207
213
mapOver(tp)
208
214
}
209
215
210
- /** Check phase consistency of terms and heal incosistent type references. */
216
+ /** Check phase consistency of terms and heal inconsistent type references. */
211
217
private def healTypeOfTerm (pos : SrcPos )(using Context ) = new TypeMap {
212
218
def apply (tp : Type ): Type =
213
219
tp match
@@ -217,14 +223,16 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
217
223
levelError(tp.symbol, tp, pos)
218
224
case tp : ThisType if level != - 1 && level != levelOf(tp.cls) =>
219
225
levelError(tp.cls, tp, pos)
226
+ case tp : AnnotatedType =>
227
+ derivedAnnotatedType(tp, apply(tp.parent), tp.annot)
220
228
case _ =>
221
229
if tp.typeSymbol.is(Package ) then tp
222
230
else mapOver(tp)
223
231
}
224
232
225
233
/** Try to heal reference to type `T` used in a higher level than its definition.
226
234
* Returns a reference to a type tag generated by `QuoteTypeTags` that contains a
227
- * refercence to a type alias containing the equivalent of `${summon[quoted.Type[T]]}`.
235
+ * reference to a type alias containing the equivalent of `${summon[quoted.Type[T]]}`.
228
236
* Emits and error if `T` cannot be healed and returns `T`.
229
237
*/
230
238
protected def tryHeal (sym : Symbol , tp : TypeRef , pos : SrcPos )(using Context ): TypeRef = {
0 commit comments