@@ -146,19 +146,23 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
146146 ttm(tree)
147147
148148 /** Transforms the given annotation tree. */
149- private def transformAnnot (annot : Tree )(using Context ): Tree = {
149+ private def transformAnnotTree (annot : Tree )(using Context ): Tree = {
150150 val saved = inJavaAnnot
151151 inJavaAnnot = annot.symbol.is(JavaDefined )
152152 if (inJavaAnnot) checkValidJavaAnnotation(annot)
153- try transform(copySymbols( annot) )
153+ try transform(annot)
154154 finally inJavaAnnot = saved
155155 }
156156
157157 private def transformAnnot (annot : Annotation )(using Context ): Annotation =
158- annot.derivedAnnotation(transformAnnot(annot.tree))
158+ val tree1 =
159+ annot match
160+ case _ : BodyAnnotation => annot.tree
161+ case _ => copySymbols(annot.tree)
162+ annot.derivedAnnotation(transformAnnotTree(tree1))
159163
160164 /** Transforms all annotations in the given type. */
161- private def transformAnnots (using Context ) =
165+ private def transformAnnotsIn (using Context ) =
162166 new TypeMap :
163167 def apply (tp : Type ) = tp match
164168 case tp @ AnnotatedType (parent, annot) =>
@@ -460,7 +464,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
460464 Checking .checkRealizable(tree.tpt.tpe, tree.srcPos, " SAM type" )
461465 super .transform(tree)
462466 case tree @ Annotated (annotated, annot) =>
463- cpy.Annotated (tree)(transform(annotated), transformAnnot (annot))
467+ cpy.Annotated (tree)(transform(annotated), transformAnnotTree (annot))
464468 case tree : AppliedTypeTree =>
465469 if (tree.tpt.symbol == defn.andType)
466470 Checking .checkNonCyclicInherited(tree.tpe, tree.args.tpes, EmptyScope , tree.srcPos)
@@ -482,7 +486,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
482486 report.error(em " type ${alias.tpe} outside bounds $bounds" , tree.srcPos)
483487 super .transform(tree)
484488 case tree : TypeTree =>
485- tree.withType(transformAnnotsIn(tpe))
489+ tree.withType(transformAnnotsIn(tree. tpe))
486490 case Typed (Ident (nme.WILDCARD ), _) =>
487491 withMode(Mode .Pattern )(super .transform(tree))
488492 // The added mode signals that bounds in a pattern need not
0 commit comments