@@ -321,16 +321,21 @@ class ReifyQuotes extends MacroTransformWithImplicits {
321321 val last = enteredSyms
322322 stats.foreach(markDef)
323323 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))) =>
325326 // To maintain phase consistency, we move the binding of the this parameter into the spliced code
326327 val (splicedBindings, stagedBindings) = bindings.partition {
327328 case vdef : ValDef => vdef.symbol.is(Synthetic ) // Assume that only _this bindings are tagged with Synthetic
328329 case _ => false
329330 }
331+
330332 val tree1 =
331333 if (level == 0 ) cpy.Inlined (tree)(call, stagedBindings, Splicer .splice(seq(splicedBindings, body)))
332334 else seq(stagedBindings, cpy.Select (expansion)(cpy.Inlined (tree)(call, splicedBindings, body), name))
333335 transform(tree1)
336+
337+ if (tree.tpe =:= defn.UnitType ) Block (tree1 :: Nil , Literal (Constant (())))
338+ else tree1
334339 case _ : Import =>
335340 tree
336341 case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
@@ -343,5 +348,20 @@ class ReifyQuotes extends MacroTransformWithImplicits {
343348 checkLevel(mapOverTree(enteredSyms))
344349 }
345350 }
351+
352+ /** InlineSplice is used to detect cases where the expansion
353+ * consists of a (possibly multiple & nested) block or a sole expression.
354+ */
355+ object InlineSplice {
356+ def unapply (tree : Tree )(implicit ctx : Context ): Option [Select ] = {
357+ tree match {
358+ case expansion : Select if expansion.symbol.isSplice =>
359+ Some (expansion)
360+ case Block (List (stat), Literal (Constant (()))) => unapply(stat)
361+ case Block (Nil , expr) => unapply(expr)
362+ case _ => None
363+ }
364+ }
365+ }
346366 }
347367}
0 commit comments