Skip to content

Commit

Permalink
Check for splices in quoted macro parameters
Browse files Browse the repository at this point in the history
Closes #12225
  • Loading branch information
nicolasstucki committed Dec 15, 2021
1 parent 5ed0586 commit a725e40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/neg-macros/i12225.scala
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit a725e40

Please sign in to comment.