Skip to content

Commit 826dd1a

Browse files
Merge pull request #8883 from dotty-staging/fix-#7442-2
Fix #7442: Only compute line numbers if the file exists
2 parents 91e049d + 391a35e commit 826dd1a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extends interfaces.SourcePosition with Showable {
2222

2323
def point: Int = span.point
2424

25-
def line: Int = if (source.exists) source.offsetToLine(point) else -1
25+
def line: Int = if (source.file.exists) source.offsetToLine(point) else -1
2626

2727
/** Extracts the lines from the underlying source file as `Array[Char]`*/
2828
def linesSlice: Array[Char] =
@@ -42,16 +42,16 @@ extends interfaces.SourcePosition with Showable {
4242
def beforeAndAfterPoint: (List[Int], List[Int]) =
4343
lineOffsets.partition(_ <= point)
4444

45-
def column: Int = if (source.exists) source.column(point) else -1
45+
def column: Int = if (source.file.exists) source.column(point) else -1
4646

4747
def start: Int = span.start
48-
def startLine: Int = if (source.exists) source.offsetToLine(start) else -1
49-
def startColumn: Int = if (source.exists) source.column(start) else -1
48+
def startLine: Int = if (source.file.exists) source.offsetToLine(start) else -1
49+
def startColumn: Int = if (source.file.exists) source.column(start) else -1
5050
def startColumnPadding: String = source.startColumnPadding(start)
5151

5252
def end: Int = span.end
53-
def endLine: Int = if (source.exists) source.offsetToLine(end) else -1
54-
def endColumn: Int = if (source.exists) source.column(end) else -1
53+
def endLine: Int = if (source.file.exists) source.offsetToLine(end) else -1
54+
def endColumn: Int = if (source.file.exists) source.column(end) else -1
5555

5656
def withOuter(outer: SourcePosition): SourcePosition = SourcePosition(source, span, outer)
5757
def withSpan(range: Span) = SourcePosition(source, range, outer)

0 commit comments

Comments
 (0)