From a725e4031da2ee3e381a9c90579bbc54475b2c8b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 15 Dec 2021 15:46:29 +0100 Subject: [PATCH] Check for splices in quoted macro parameters Closes #12225 --- compiler/src/dotty/tools/dotc/transform/Splicer.scala | 9 ++++++++- tests/neg-macros/i12225.scala | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/neg-macros/i12225.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 06162ef513fa..49b6f5564620 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -149,7 +149,14 @@ object Splicer { case Typed(expr, _) => checkIfValidArgument(expr) case Apply(Select(Apply(fn, quoted :: Nil), nme.apply), _) if fn.symbol == defn.QuotedRuntime_exprQuote => - // OK + val noSpliceChecker = new TreeTraverser { + def traverse(tree: Tree)(using Context): Unit = tree match + case Spliced(_) => + report.error("Quoted argument of macros may not have splices", tree.srcPos) + case _ => + traverseChildren(tree) + } + noSpliceChecker.traverse(quoted) case Apply(TypeApply(fn, List(quoted)), _)if fn.symbol == defn.QuotedTypeModule_of => // OK diff --git a/tests/neg-macros/i12225.scala b/tests/neg-macros/i12225.scala new file mode 100644 index 000000000000..66d619aad634 --- /dev/null +++ b/tests/neg-macros/i12225.scala @@ -0,0 +1,7 @@ +object TestMacro { + inline def test[T](inline t: T): T = ${ identity('{ identity(${ identity('{ identity(${ identity('t) }) }) }) }) } // error +} + +object Test { + TestMacro.test("x") +}