Skip to content

Commit 0f8ff8d

Browse files
committed
Add missing Inlined nodes on quotes
1 parent dc46be9 commit 0f8ff8d

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
391391
case SeqLiteral(elems, elemtpt) =>
392392
"[" ~ toTextGlobal(elems, ",") ~ " : " ~ toText(elemtpt) ~ "]"
393393
case tree @ Inlined(call, bindings, body) =>
394-
(("/* inlined from " ~ toText(call) ~ " */ ") `provided`
395-
!call.isEmpty && !homogenizedView && !ctx.settings.YshowNoInline.value) ~
394+
(("/* inlined from " ~ (if (call.isEmpty) "outside" else toText(call)) ~ " */ ") `provided`
395+
!homogenizedView && !ctx.settings.YshowNoInline.value) ~
396396
blockText(bindings :+ body)
397397
case tpt: untpd.DerivedTypeTree =>
398398
"<derived typetree watching " ~ summarized(toText(tpt.watched)) ~ ">"

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,20 @@ class ReifyQuotes extends MacroTransformWithImplicits {
372372
capturers(body.symbol)(body)
373373
case _=>
374374
val (body1, splices) = nested(isQuote = true).split(body)
375-
if (level == 0 && !ctx.inRewriteMethod) pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos)
375+
if (level == 0 && !ctx.inRewriteMethod) {
376+
val body2 =
377+
if (body1.isType) body1
378+
else {
379+
// Leave only a call trace consisting of
380+
// - a reference to the top-level class from which the call was inlined,
381+
// - the call's position
382+
// in the call field of an Inlined node.
383+
// The trace has enough info to completely reconstruct positions.
384+
val callTrace = Ident(ctx.owner.topLevelClass.typeRef).withPos(body1.pos)
385+
Inlined(callTrace, Nil, body1)
386+
}
387+
pickledQuote(body2, splices, body.tpe, isType).withPos(quote.pos)
388+
}
376389
else {
377390
// In top-level splice in a rewrite def. Keep the tree as it is, it will be transformed at inline site.
378391
body

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ object Splicer {
4040
val interpreter = new Interpreter(pos, classLoader)
4141
try {
4242
// Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree
43-
val interpreted = interpreter.interpret[scala.quoted.Expr[Any]](tree)
44-
interpreted.fold(tree)(x => PickledQuotes.quotedExprToTree(x))
43+
val interpretedExpr = interpreter.interpret[scala.quoted.Expr[Any]](tree)
44+
val interpretedTree = interpretedExpr.fold(tree)(x => PickledQuotes.quotedExprToTree(x))
45+
// Cancel the current inline trace. The interpreted tree will start with it's own trace.
46+
Inlined(EmptyTree, Nil, interpretedTree)
4547
}
4648
catch {
4749
case ex: scala.quoted.QuoteError =>
@@ -286,8 +288,6 @@ object Splicer {
286288
case NamedArg(_, arg) => interpretTree(arg)
287289
case Ident(name) if env.contains(name) => env(name)
288290

289-
case Inlined(EmptyTree, Nil, expansion) => interpretTree(expansion)
290-
291291
case _ => unexpectedTree(tree)
292292
}
293293

tests/run/i4947e.check

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ true
33
assertImpl: Test$.main(Test_2.scala:8)
44
false
55
assertImpl: Test$.main(Test_2.scala:9)
6-
hi: Test$.main(Test_2.scala:9)
6+
hi: Test$.main(Test_2.scala:10)
7+
hi again: Test$.main(Test_2.scala:11)
78
false

tests/run/i4947e/Test_2.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ object Test {
66
val x = 1
77
assert2(x != 0)
88
assert2(x == 0)
9-
assert2 { Macros.printStack("hi"); x == 0 }
9+
assert2 {
10+
Macros.printStack("hi")
11+
Macros.printStack("hi again")
12+
x == 0
13+
}
1014
}
1115
}

0 commit comments

Comments
 (0)