@@ -43,6 +43,7 @@ trait MessageRendering {
43
43
* @return (lines before error, lines after error, line numbers offset)
44
44
*/
45
45
def sourceLines (pos : SourcePosition , diagnosticLevel : String )(implicit ctx : Context ): (List [String ], List [String ], Int ) = {
46
+ assert(pos.exists && pos.source.file.exists)
46
47
var maxLen = Int .MinValue
47
48
def render (offsetAndLine : (Int , String )): String = {
48
49
val (offset, line) = offsetAndLine
@@ -113,7 +114,9 @@ trait MessageRendering {
113
114
*/
114
115
def posStr (pos : SourcePosition , diagnosticLevel : String , message : Message )(implicit ctx : Context ): String =
115
116
if (pos.exists) hl(diagnosticLevel)({
116
- val file = s " ${pos.source.file.toString}: ${pos.line + 1 }: ${pos.column}"
117
+ val file =
118
+ if (pos.source.file.exists) s " ${pos.source.file.toString}: ${pos.line + 1 }: ${pos.column}"
119
+ else s " ${pos.source.file.toString}: offset ${pos.start} (missing source file) "
117
120
val errId =
118
121
if (message.errorId ne ErrorMessageID .NoExplanationID ) {
119
122
val errorNumber = message.errorId.errorNumber()
@@ -145,7 +148,7 @@ trait MessageRendering {
145
148
val sb = mutable.StringBuilder .newBuilder
146
149
val posString = posStr(pos, diagnosticLevel, msg)
147
150
if (posString.nonEmpty) sb.append(posString).append(EOL )
148
- if (pos.exists) {
151
+ if (pos.exists && pos.source.file.exists ) {
149
152
val (srcBefore, srcAfter, offset) = sourceLines(pos, diagnosticLevel)
150
153
val marker = columnMarker(pos, offset, diagnosticLevel)
151
154
val err = errorMsg(pos, msg.msg, offset)
0 commit comments