Skip to content

Commit f32e204

Browse files
committed
Split annotation splice transformation from type healing
1 parent bd5e3b0 commit f32e204

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ class PCPCheckAndHeal extends TreeMapWithStages {
5959
checkAnnotations(tree)
6060
super.transform(tree)
6161
else tree match {
62-
63-
case _: TypeTree | _: RefTree if tree.isType =>
62+
case _: TypeTree =>
63+
val tp1 = transformTypeAnnotationSplices(tree.tpe)
64+
val healedType = healType(tree.srcPos)(tp1)
65+
if healedType == tree.tpe then tree
66+
else TypeTree(healedType).withSpan(tree.span)
67+
case _: RefTree if tree.isType =>
6468
val healedType = healType(tree.srcPos)(tree.tpe)
6569
if healedType == tree.tpe then tree
6670
else TypeTree(healedType).withSpan(tree.span)
@@ -163,6 +167,15 @@ class PCPCheckAndHeal extends TreeMapWithStages {
163167
ref(tagRef).withSpan(splice.span)
164168
}
165169

170+
def transformTypeAnnotationSplices(tp: Type)(using Context) = new TypeMap {
171+
def apply(tp: Type): Type = tp match
172+
case tp: AnnotatedType =>
173+
val newAnnotTree = transform(tp.annot.tree)
174+
derivedAnnotatedType(tp, apply(tp.parent), tp.annot.derivedAnnotation(newAnnotTree))
175+
case _ =>
176+
mapOver(tp)
177+
}.apply(tp)
178+
166179
/** Check that annotations do not contain quotes and and that splices are valid */
167180
private def checkAnnotations(tree: Tree)(using Context): Unit =
168181
tree match
@@ -198,8 +211,7 @@ class PCPCheckAndHeal extends TreeMapWithStages {
198211
case tp @ TermRef(NoPrefix, _) if !tp.symbol.isStatic && level > levelOf(tp.symbol) =>
199212
levelError(tp.symbol, tp, pos)
200213
case tp: AnnotatedType =>
201-
val newAnnotTree = transform(tp.annot.tree)
202-
derivedAnnotatedType(tp, apply(tp.parent), tp.annot.derivedAnnotation(newAnnotTree))
214+
derivedAnnotatedType(tp, apply(tp.parent), tp.annot)
203215
case _ =>
204216
mapOver(tp)
205217

0 commit comments

Comments
 (0)