Skip to content

Commit 16c98cd

Browse files
committed
Pull inlined bindings under a splice
1 parent dfaa965 commit 16c98cd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class ReifyQuotes extends MacroTransform {
2121

2222
protected def newTransformer(implicit ctx: Context): Transformer = new Reifier
2323

24+
/** is tree splice operation? */
25+
def isSplice(tree: Select)(implicit ctx: Context) =
26+
tree.symbol == defn.QuotedExpr_~ || tree.symbol == defn.QuotedType_~
27+
2428
/** Serialize `tree`. Embedded splices are represented as nodes of the form
2529
*
2630
* Select(qual, sym)
@@ -112,8 +116,7 @@ class ReifyQuotes extends MacroTransform {
112116
inQuote(reifyCall(transform(arg), isType = false))
113117
case TypeApply(fn, arg :: Nil) if fn.symbol == defn.typeQuoteMethod =>
114118
inQuote(reifyCall(transform(arg), isType = true))
115-
case Select(body, name)
116-
if tree.symbol == defn.QuotedExpr_~ || tree.symbol == defn.QuotedType_~ =>
119+
case tree @ Select(body, name) if isSplice(tree) =>
117120
currentLevel -= 1
118121
val body1 = try transform(body) finally currentLevel += 1
119122
if (currentLevel > 0) {
@@ -140,6 +143,10 @@ class ReifyQuotes extends MacroTransform {
140143
levelOf -= enteredSyms.head
141144
enteredSyms = enteredSyms.tail
142145
}
146+
case Inlined(call, bindings, expansion @ Select(body, name)) if isSplice(expansion) =>
147+
// To maintain phase consistency, convert inlined expressions of the form
148+
// `{ bindings; ~expansion }` to `~{ bindings; expansion }`
149+
cpy.Select(expansion)(cpy.Inlined(tree)(call, bindings, body), name)
143150
case _: Import =>
144151
tree
145152
case _ =>

0 commit comments

Comments
 (0)