Skip to content

Commit fee34a9

Browse files
Merge pull request #14117 from dotty-staging/fix-#12225
Check for splices in quoted macro parameters
2 parents 0857285 + a725e40 commit fee34a9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ object Splicer {
149149
case Typed(expr, _) => checkIfValidArgument(expr)
150150

151151
case Apply(Select(Apply(fn, quoted :: Nil), nme.apply), _) if fn.symbol == defn.QuotedRuntime_exprQuote =>
152-
// OK
152+
val noSpliceChecker = new TreeTraverser {
153+
def traverse(tree: Tree)(using Context): Unit = tree match
154+
case Spliced(_) =>
155+
report.error("Quoted argument of macros may not have splices", tree.srcPos)
156+
case _ =>
157+
traverseChildren(tree)
158+
}
159+
noSpliceChecker.traverse(quoted)
153160

154161
case Apply(TypeApply(fn, List(quoted)), _)if fn.symbol == defn.QuotedTypeModule_of =>
155162
// OK

tests/neg-macros/i12225.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object TestMacro {
2+
inline def test[T](inline t: T): T = ${ identity('{ identity(${ identity('{ identity(${ identity('t) }) }) }) }) } // error
3+
}
4+
5+
object Test {
6+
TestMacro.test("x")
7+
}

0 commit comments

Comments
 (0)