@@ -23,6 +23,7 @@ import dotty.tools.dotc.typer.Inliner
23
23
24
24
import scala .collection .mutable
25
25
import dotty .tools .dotc .util .SourcePosition
26
+ import dotty .tools .dotc .util .Property
26
27
27
28
import scala .annotation .constructorOnly
28
29
@@ -33,20 +34,25 @@ import scala.annotation.constructorOnly
33
34
class PCPCheckAndHeal (@ constructorOnly ictx : Context ) extends TreeMapWithStages (ictx) {
34
35
import tpd ._
35
36
37
+ private val InAnnotation = Property .Key [Unit ]()
38
+
36
39
override def transform (tree : Tree )(implicit ctx : Context ): Tree =
37
40
if (tree.source != ctx.source && tree.source.exists)
38
41
transform(tree)(ctx.withSource(tree.source))
39
42
else tree match {
40
43
case tree : DefDef if tree.symbol.is(Inline ) && level > 0 => EmptyTree
41
44
case tree : DefTree =>
45
+ lazy val annotCtx = ctx.fresh.setProperty(InAnnotation , ()).withOwner(tree.symbol)
42
46
for (annot <- tree.symbol.annotations)
43
- transform(annot.tree)(given ctx .withOwner(tree.symbol) )
47
+ transform(annot.tree)(given annotCtx )
44
48
checkLevel(super .transform(tree))
45
49
case _ => checkLevel(super .transform(tree))
46
50
}
47
51
48
52
/** Transform quoted trees while maintaining phase correctness */
49
53
override protected def transformQuotation (body : Tree , quote : Tree )(implicit ctx : Context ): Tree = {
54
+ if (ctx.property(InAnnotation ).isDefined)
55
+ ctx.error(" Cannot have a quote in an annotation" , quote.sourcePos)
50
56
val body1 = transform(body)(quoteContext)
51
57
super .transformQuotation(body1, quote)
52
58
}
0 commit comments