Skip to content

Commit 915ff94

Browse files
committed
Harden withStart and friends for Positions
They used to crash when applied to NoPosition. We now handle this case gracefully.
1 parent a082b9c commit 915ff94

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler/src/dotty/tools/dotc/util/Positions.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ object Positions {
100100

101101
/** A copy of this position with a different start */
102102
def withStart(start: Int) =
103-
fromOffsets(start, this.end, if (isSynthetic) SyntheticPointDelta else this.point - start)
103+
if (exists) fromOffsets(start, this.end, if (isSynthetic) SyntheticPointDelta else this.point - start)
104+
else this
104105

105106
/** A copy of this position with a different end */
106-
def withEnd(end: Int) = fromOffsets(this.start, end, pointDelta)
107+
def withEnd(end: Int) =
108+
if (exists) fromOffsets(this.start, end, pointDelta)
109+
else this
107110

108111
/** A copy of this position with a different point */
109-
def withPoint(point: Int) = fromOffsets(this.start, this.end, point - this.start)
112+
def withPoint(point: Int) =
113+
if (exists) fromOffsets(this.start, this.end, point - this.start)
114+
else this
110115

111116
/** A synthetic copy of this position */
112117
def toSynthetic = if (isSynthetic) this else Position(start, end)

0 commit comments

Comments
 (0)