@@ -321,16 +321,22 @@ class ReifyQuotes extends MacroTransformWithImplicits {
321
321
val last = enteredSyms
322
322
stats.foreach(markDef)
323
323
mapOverTree(last)
324
- case Inlined (call, bindings, expansion @ Select (body, name)) if expansion.symbol.isSplice =>
324
+
325
+ case Inlined (call, bindings, InlineSplice (expansion @ Select (body, name))) =>
325
326
// To maintain phase consistency, we move the binding of the this parameter into the spliced code
326
327
val (splicedBindings, stagedBindings) = bindings.partition {
327
328
case vdef : ValDef => vdef.symbol.is(Synthetic ) // Assume that only _this bindings are tagged with Synthetic
328
329
case _ => false
329
330
}
331
+
330
332
val tree1 =
331
333
if (level == 0 ) cpy.Inlined (tree)(call, stagedBindings, Splicer .splice(seq(splicedBindings, body)))
332
334
else seq(stagedBindings, cpy.Select (expansion)(cpy.Inlined (tree)(call, splicedBindings, body), name))
333
- transform(tree1)
335
+ val tree2 = transform(tree1)
336
+
337
+ // due to value-discarding which converts an { e } into { e; () })
338
+ if (tree.tpe =:= defn.UnitType ) Block (tree2 :: Nil , Literal (Constant (())))
339
+ else tree2
334
340
case _ : Import =>
335
341
tree
336
342
case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
@@ -343,5 +349,20 @@ class ReifyQuotes extends MacroTransformWithImplicits {
343
349
checkLevel(mapOverTree(enteredSyms))
344
350
}
345
351
}
352
+
353
+ /** InlineSplice is used to detect cases where the expansion
354
+ * consists of a (possibly multiple & nested) block or a sole expression.
355
+ */
356
+ object InlineSplice {
357
+ def unapply (tree : Tree )(implicit ctx : Context ): Option [Select ] = {
358
+ tree match {
359
+ case expansion : Select if expansion.symbol.isSplice =>
360
+ Some (expansion)
361
+ case Block (List (stat), Literal (Constant (()))) => unapply(stat)
362
+ case Block (Nil , expr) => unapply(expr)
363
+ case _ => None
364
+ }
365
+ }
366
+ }
346
367
}
347
368
}
0 commit comments