@@ -3,6 +3,7 @@ package transform
33
44import dotty .tools .dotc .ast .Trees ._
55import dotty .tools .dotc .ast .{TreeTypeMap , tpd , untpd }
6+ import dotty .tools .dotc .core .Annotations .BodyAnnotation
67import dotty .tools .dotc .core .Constants ._
78import dotty .tools .dotc .core .Contexts ._
89import dotty .tools .dotc .core .Decorators ._
@@ -23,6 +24,7 @@ import dotty.tools.dotc.typer.Inliner
2324
2425import scala .collection .mutable
2526import dotty .tools .dotc .util .SourcePosition
27+ import dotty .tools .dotc .util .Property
2628
2729import scala .annotation .constructorOnly
2830
@@ -33,20 +35,27 @@ import scala.annotation.constructorOnly
3335class PCPCheckAndHeal (@ constructorOnly ictx : Context ) extends TreeMapWithStages (ictx) {
3436 import tpd ._
3537
38+ private val InAnnotation = Property .Key [Unit ]()
39+
3640 override def transform (tree : Tree )(implicit ctx : Context ): Tree =
3741 if (tree.source != ctx.source && tree.source.exists)
3842 transform(tree)(ctx.withSource(tree.source))
3943 else tree match {
4044 case tree : DefDef if tree.symbol.is(Inline ) && level > 0 => EmptyTree
4145 case tree : DefTree =>
42- for (annot <- tree.symbol.annotations)
43- transform(annot.tree)(given ctx .withOwner(tree.symbol))
46+ lazy val annotCtx = ctx.fresh.setProperty(InAnnotation , true ).withOwner(tree.symbol)
47+ for (annot <- tree.symbol.annotations) annot match {
48+ case annot : BodyAnnotation => annot // already checked in PrepareInlineable before the creation of the BodyAnnotation
49+ case annot => transform(annot.tree)(given annotCtx )
50+ }
4451 checkLevel(super .transform(tree))
4552 case _ => checkLevel(super .transform(tree))
4653 }
4754
4855 /** Transform quoted trees while maintaining phase correctness */
4956 override protected def transformQuotation (body : Tree , quote : Tree )(implicit ctx : Context ): Tree = {
57+ if (ctx.property(InAnnotation ).isDefined)
58+ ctx.error(" Cannot have a quote in an annotation" , quote.sourcePos)
5059 val body1 = transform(body)(quoteContext)
5160 super .transformQuotation(body1, quote)
5261 }
0 commit comments