@@ -73,7 +73,7 @@ import dotty.tools.dotc.core.quoted._
73
73
* ...
74
74
* val y1$1 = args(1).asInstanceOf[Expr[Y]]
75
75
* ...
76
- * { ... T1$1.unary_~ ... x ... '( y1$1.unary_~) ... }
76
+ * { ... x1$1 .... '{ ... T1$1.unary_~ ... x1$1.toExpr.unary_~ ... y1$1.unary_~ ... } ... }
77
77
* }
78
78
* ```
79
79
* Note: the parameters of `foo` are kept for simple overloading resolution but they are not used in the body of `foo`.
@@ -375,9 +375,15 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
375
375
}
376
376
else body match {
377
377
case body : RefTree if isCaptured(body, level + 1 ) =>
378
- // Optimization: avoid the full conversion when capturing `x`
379
- // in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
380
- capturers(body.symbol)(body)
378
+ if (body.symbol.is(Inline )) {
379
+ // Optimization: avoid the full conversion when capturing inlined `x`
380
+ // in '{ x } to '{ x$1.toExpr.unary_~ } and go directly to `x$1.toExpr`
381
+ liftValue(capturers(body.symbol)(body))
382
+ } else {
383
+ // Optimization: avoid the full conversion when capturing `x`
384
+ // in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
385
+ capturers(body.symbol)(body)
386
+ }
381
387
case _=>
382
388
val (body1, splices) = nested(isQuote = true ).split(body)
383
389
pickledQuote(body1, splices, isType).withPos(quote.pos)
@@ -546,8 +552,11 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
546
552
splice(tree)
547
553
case tree : RefTree if isCaptured(tree, level) =>
548
554
val capturer = capturers(tree.symbol)
549
- if (tree.symbol.is(Inline )) capturer(tree)
550
- else splice(capturer(tree).select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
555
+ def captureAndSplice (t : Tree ) =
556
+ splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
557
+ if (tree.symbol.is(Inline ) && level == 0 ) capturer(tree)
558
+ else if (tree.symbol.is(Inline )) captureAndSplice(liftValue(capturer(tree)))
559
+ else captureAndSplice(capturer(tree))
551
560
case Block (stats, _) =>
552
561
val last = enteredSyms
553
562
stats.foreach(markDef)
@@ -601,6 +610,21 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
601
610
}
602
611
}
603
612
613
+ private def liftValue (tree : Tree )(implicit ctx : Context ): Tree = {
614
+ val reqType = defn.QuotedLiftableType .appliedTo(tree.tpe.widen)
615
+ val liftable = ctx.typer.inferImplicitArg(reqType, tree.pos)
616
+ liftable.tpe match {
617
+ case fail : SearchFailureType =>
618
+ ctx.error(i """
619
+ |
620
+ | The access would be accepted with the right Liftable, but
621
+ | ${ctx.typer.missingArgMsg(liftable, reqType, " " )}""" )
622
+ EmptyTree
623
+ case _ =>
624
+ liftable.select(" toExpr" .toTermName).appliedTo(tree)
625
+ }
626
+ }
627
+
604
628
private def liftList (list : List [Tree ], tpe : Type )(implicit ctx : Context ): Tree = {
605
629
list.foldRight[Tree ](ref(defn.NilModule )) { (x, acc) =>
606
630
acc.select(" ::" .toTermName).appliedToType(tpe).appliedTo(x)
0 commit comments