Skip to content

Commit 1eab199

Browse files
committed
Do not stage bindings for inlined parameters inside quotes
1 parent 6c7ac49 commit 1eab199

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,15 @@ class ReifyQuotes extends MacroTransformWithImplicits {
322322
stats.foreach(markDef)
323323
mapOverTree(last)
324324
case Inlined(call, bindings, expansion @ Select(body, name)) if expansion.symbol.isSplice =>
325-
if (level == 0) {
326-
// To maintain phase consistency, we move the binding of the this parameter into the spliced code
327-
val (thisBindings, otherBindings) = bindings.partition {
328-
case vdef: ValDef => vdef.symbol.is(Synthetic) // Assume that only _this bindings are tagged with Synthetic
329-
case _ => false
330-
}
331-
val splicedBody = Splicer.splice(seq(thisBindings, body))
332-
transform(cpy.Inlined(tree)(call, otherBindings, splicedBody))
333-
} else {
334-
// To maintain phase consistency, convert inlined expressions of the form
335-
// `{ bindings; ~expansion }` to `~{ bindings; expansion }`
336-
transform(cpy.Select(expansion)(cpy.Inlined(tree)(call, bindings, body), name))
325+
// To maintain phase consistency, we move the binding of the this parameter into the spliced code
326+
val (thisBindings, otherBindings) = bindings.partition {
327+
case vdef: ValDef => vdef.symbol.is(Synthetic) // Assume that only _this bindings are tagged with Synthetic
328+
case _ => false
337329
}
330+
val tree1 =
331+
if (level == 0) cpy.Inlined(tree)(call, otherBindings, Splicer.splice(seq(thisBindings, body)))
332+
else seq(otherBindings, cpy.Select(expansion)(cpy.Inlined(tree)(call, thisBindings, body), name))
333+
transform(tree1)
338334
case _: Import =>
339335
tree
340336
case tree: DefDef if tree.symbol.is(Macro) && level == 0 =>

tests/pos/i3898c/quoted_1.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted._
2+
object Macro {
3+
inline def ff(x: Int, inline y: Int): String = ~impl('(x))
4+
def impl(x: Expr[Int]): Expr[String] = ""
5+
}

tests/pos/i3898c/quoted_2.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
val a = '{
4+
def z: Int = 5
5+
Macro.ff(z, 5)
6+
}
7+
8+
}
9+
}

0 commit comments

Comments
 (0)