Skip to content

Commit 8c2104a

Browse files
committed
sometimes files do not exist for positions
1 parent 9c22ce7 commit 8c2104a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ trait MessageRendering {
149149
if (posString.nonEmpty) sb.append(posString).append(EOL)
150150
if (pos.exists) {
151151
val pos1 = pos.nonInlined
152-
val (srcBefore, srcAfter, offset) = sourceLines(pos1, diagnosticLevel)
153-
val marker = columnMarker(pos1, offset, diagnosticLevel)
154-
val err = errorMsg(pos1, msg.message, offset)
155-
sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1)) ::: srcAfter).mkString(EOL))
152+
if (pos1.exists && pos1.source.file.exists) {
153+
val (srcBefore, srcAfter, offset) = sourceLines(pos1, diagnosticLevel)
154+
val marker = columnMarker(pos1, offset, diagnosticLevel)
155+
val err = errorMsg(pos1, msg.message, offset)
156+
sb.append((srcBefore ::: marker :: err :: outer(pos, " " * (offset - 1)) ::: srcAfter).mkString(EOL))
157+
}
158+
else sb.append(msg.message)
156159
}
157160
else sb.append(msg.message)
158161
sb.toString

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class SourceFile(val file: AbstractFile, computeContent: => Array[Char]) extends
196196
var idx = startOfLine(offset)
197197
var col = 0
198198
while (idx != offset) {
199-
col += (if (idx < length && content()(idx) == '\t') (tabInc - col) % tabInc else 1)
199+
col += (if (idx < content().length && content()(idx) == '\t') (tabInc - col) % tabInc else 1)
200200
idx += 1
201201
}
202202
col
@@ -285,4 +285,3 @@ object SourceFile {
285285
override def exists: Boolean = false
286286
override def atSpan(span: Span): SourcePosition = NoSourcePosition
287287
}
288-

0 commit comments

Comments
 (0)