@@ -3,6 +3,7 @@ package transform
3
3
4
4
import dotty .tools .dotc .ast .Trees ._
5
5
import dotty .tools .dotc .ast .{TreeTypeMap , tpd , untpd }
6
+ import dotty .tools .dotc .core .Annotations .BodyAnnotation
6
7
import dotty .tools .dotc .core .Constants ._
7
8
import dotty .tools .dotc .core .Contexts ._
8
9
import dotty .tools .dotc .core .Decorators ._
@@ -23,6 +24,7 @@ import dotty.tools.dotc.typer.Inliner
23
24
24
25
import scala .collection .mutable
25
26
import dotty .tools .dotc .util .SourcePosition
27
+ import dotty .tools .dotc .util .Property
26
28
27
29
import scala .annotation .constructorOnly
28
30
@@ -33,20 +35,27 @@ import scala.annotation.constructorOnly
33
35
class PCPCheckAndHeal (@ constructorOnly ictx : Context ) extends TreeMapWithStages (ictx) {
34
36
import tpd ._
35
37
38
+ private val InAnnotation = Property .Key [Unit ]()
39
+
36
40
override def transform (tree : Tree )(implicit ctx : Context ): Tree =
37
41
if (tree.source != ctx.source && tree.source.exists)
38
42
transform(tree)(ctx.withSource(tree.source))
39
43
else tree match {
40
44
case tree : DefDef if tree.symbol.is(Inline ) && level > 0 => EmptyTree
41
45
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
+ }
44
51
checkLevel(super .transform(tree))
45
52
case _ => checkLevel(super .transform(tree))
46
53
}
47
54
48
55
/** Transform quoted trees while maintaining phase correctness */
49
56
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)
50
59
val body1 = transform(body)(quoteContext)
51
60
super .transformQuotation(body1, quote)
52
61
}
0 commit comments