Skip to content

Commit 24b0d82

Browse files
committed
Fix #4947: Do not replace positions of inlined arguments
1 parent 01c5eac commit 24b0d82

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,26 @@ object Inliner {
149149

150150
/** Replace `Inlined` node by a block that contains its bindings and expansion */
151151
def dropInlined(inlined: tpd.Inlined)(implicit ctx: Context): Tree = {
152-
val reposition = new TreeMap {
153-
override def transform(tree: Tree)(implicit ctx: Context): Tree = {
154-
super.transform(tree).withPos(inlined.call.pos)
152+
if (enclosingInlineds.nonEmpty) inlined // remove in the outer inlined call
153+
else {
154+
val reposition = new TreeMap {
155+
private[this] var pos: Position = inlined.pos
156+
override def transform(tree: Tree)(implicit ctx: Context): Tree = {
157+
tree match {
158+
case inlined: Inlined =>
159+
val last = pos
160+
pos = inlined.call.pos
161+
val res = tpd.seq(inlined.bindings.map(transform), transform(inlined.expansion)).withPos(last)
162+
pos = last
163+
res
164+
case tree =>
165+
if (pos.exists) super.transform(tree).withPos(pos)
166+
else super.transform(tree)
167+
}
168+
}
155169
}
170+
reposition.transform(inlined)
156171
}
157-
tpd.seq(inlined.bindings, reposition.transform(inlined.expansion))
158172
}
159173
}
160174

tests/run/i4947.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
failed
2+
Test$.main(i4947.scala:9)

tests/run/i4947.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object Test {
2+
3+
transparent def track[T](f: => T): T = f
4+
5+
def main(args: Array[String]): Unit = {
6+
try {
7+
track {
8+
val a = 9
9+
throw new Exception("failed")
10+
}
11+
} catch {
12+
case ex: Throwable =>
13+
println(ex.getMessage)
14+
println(ex.getStackTrace.head)
15+
}
16+
}
17+
18+
}

0 commit comments

Comments
 (0)