Skip to content

Commit 3a6b56b

Browse files
Nicolas StuckiNicolas Stucki
Nicolas Stucki
authored and
Nicolas Stucki
committed
Use enclosingInlineds directly to know the position
1 parent 24b0d82 commit 3a6b56b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,25 @@ object Inliner {
151151
def dropInlined(inlined: tpd.Inlined)(implicit ctx: Context): Tree = {
152152
if (enclosingInlineds.nonEmpty) inlined // remove in the outer inlined call
153153
else {
154-
val reposition = new TreeMap {
155-
private[this] var pos: Position = inlined.pos
154+
class Reposition extends TreeMap {
156155
override def transform(tree: Tree)(implicit ctx: Context): Tree = {
157156
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)
157+
case tree: Inlined => transformInline(tree)
158+
case _ =>
159+
val transformed = super.transform(tree)
160+
enclosingInlineds match {
161+
case call :: _ if !call.isEmpty =>
162+
// This tree was inlined and will have the position of the call that was inlined
163+
transformed.withPos(call.pos)
164+
case _ => transformed
165+
}
167166
}
168167
}
168+
def transformInline(tree: tpd.Inlined)(implicit ctx: Context): Tree = {
169+
tpd.seq(transformSub(tree.bindings), transform(tree.expansion)(inlineContext(tree.call)))
170+
}
169171
}
170-
reposition.transform(inlined)
172+
(new Reposition).transformInline(inlined)
171173
}
172174
}
173175
}

0 commit comments

Comments
 (0)