Skip to content

Commit 4172269

Browse files
committed
Strip annotations from the type of a quoted expression
These annotations may contain spliced expression that would leak out of the quote if not stripped. See `tests/pos-macros/i7519b.scala`.
1 parent 28676ae commit 4172269

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
103103
if (ctx.property(InAnnotation).isDefined)
104104
report.error("Cannot have a quote in an annotation", quote.srcPos)
105105

106+
val stripAnnotsDeep: TypeMap = new TypeMap:
107+
def apply(tp: Type): Type = mapOver(tp.stripAnnots)
108+
106109
val contextWithQuote =
107110
if level == 0 then contextWithQuoteTypeTags(taggedTypes)(using quoteContext)
108111
else quoteContext
@@ -115,7 +118,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
115118
if body.isTerm then
116119
// `quoted.runtime.Expr.quote[T](<body>)` --> `quoted.runtime.Expr.quote[T2](<body2>)`
117120
val TypeApply(fun, targs) = quote.fun: @unchecked
118-
val targs2 = targs.map(targ => TypeTree(healTypeOfTerm(quote.fun.srcPos)(targ.tpe)))
121+
val targs2 = targs.map(targ => TypeTree(healTypeOfTerm(quote.fun.srcPos)(stripAnnotsDeep(targ.tpe))))
119122
cpy.Apply(quote)(cpy.TypeApply(quote.fun)(fun, targs2), body2 :: Nil)
120123
else
121124
val quotes = quote.args.mapConserve(transform)

0 commit comments

Comments
 (0)