Skip to content

Commit

Permalink
Merge pull request #14117 from dotty-staging/fix-#12225
Browse files Browse the repository at this point in the history
Check for splices in quoted macro parameters
  • Loading branch information
anatoliykmetyuk authored Dec 17, 2021
2 parents 0857285 + a725e40 commit fee34a9
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 fee34a9

Please sign in to comment.