Skip to content

Commit 2ada3f6

Browse files
committed
Preserve zero-extent positions when setting children positions
If a tree has no position or a zero-extent position, it should be synthetic. We can preserve this invariant by always setting a zero-extent position for these trees here.
1 parent b3befee commit 2ada3f6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ abstract class Positioned extends DotClass with Product {
7272
// is known, from left to right.
7373
def fillIn(ps: List[Positioned], start: Int, end: Int): Unit = ps match {
7474
case p :: ps1 =>
75-
p.setPos(Position(start, end))
76-
fillIn(ps1, end, end)
75+
// If a tree has no position or a zero-extent position, it should be
76+
// synthetic. We can preserve this invariant by always setting a
77+
// zero-extent position for these trees here.
78+
if (!p.pos.exists || p.pos.isZeroExtent) {
79+
p.setPos(Position(start, start))
80+
fillIn(ps1, start, end)
81+
} else {
82+
p.setPos(Position(start, end))
83+
fillIn(ps1, end, end)
84+
}
7785
case nil =>
7886
}
7987
while (true) {

0 commit comments

Comments
 (0)