@@ -15,6 +15,7 @@ import typer.Implicits.SearchFailureType
1515import scala .collection .mutable
1616import dotty .tools .dotc .core .StdNames ._
1717import dotty .tools .dotc .core .quoted ._
18+ import dotty .tools .dotc .typer .Inliner
1819import dotty .tools .dotc .util .SourcePosition
1920
2021
@@ -381,7 +382,12 @@ class Staging extends MacroTransformWithImplicits {
381382 capturers(body.symbol)(body)
382383 case _=>
383384 val (body1, splices) = nested(isQuote = true ).split(body)
384- if (level == 0 && ! ctx.inInlineMethod) pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos)
385+ if (level == 0 && ! ctx.inInlineMethod) {
386+ val body2 =
387+ if (body1.isType) body1
388+ else Inlined (Inliner .inlineCallTrace(ctx.owner, quote.pos), Nil , body1)
389+ pickledQuote(body2, splices, body.tpe, isType).withPos(quote.pos)
390+ }
385391 else {
386392 // In top-level splice in an inline def. Keep the tree as it is, it will be transformed at inline site.
387393 body
@@ -432,7 +438,13 @@ class Staging extends MacroTransformWithImplicits {
432438 else if (level == 1 ) {
433439 val (body1, quotes) = nested(isQuote = false ).split(splice.qualifier)
434440 val tpe = outer.embedded.getHoleType(splice)
435- makeHole(body1, quotes, tpe).withPos(splice.pos)
441+ val hole = makeHole(body1, quotes, tpe).withPos(splice.pos)
442+ // We do not place add the inline marker for trees that where lifted as they come from the same file as their
443+ // enclosing quote. Any intemediate splice will add it's own Inlined node and cancel it before splicig the lifted tree.
444+ // Note that lifted trees are not necessarily expressions and that Inlined nodes are expected to be expressions.
445+ // For example we can have a lifted tree containing the LHS of an assignment (see tests/run-with-compiler/quote-var.scala).
446+ if (splice.isType || outer.embedded.isLiftedSymbol(splice.qualifier.symbol)) hole
447+ else Inlined (EmptyTree , Nil , hole)
436448 }
437449 else if (enclosingInlineds.nonEmpty) { // level 0 in an inlined call
438450 val spliceCtx = ctx.outer // drop the last `inlineContext`
@@ -664,7 +676,12 @@ object Staging {
664676 map.get(splice.qualifier.symbol).map(_.tpe.widen).getOrElse(splice.tpe)
665677 }
666678
679+ def isLiftedSymbol (sym : Symbol )(implicit ctx : Context ): Boolean = map.contains(sym)
680+
667681 /** Get the list of embedded trees */
668682 def getTrees : List [tpd.Tree ] = trees.toList
683+
684+ override def toString : String = s " Embedded( $trees, $map) "
685+
669686 }
670687}
0 commit comments