diff options
| -rw-r--r-- | source/compiler-core/slang-lexer-diagnostic-defs.h | 1 | ||||
| -rw-r--r-- | source/compiler-core/slang-lexer.cpp | 4 | ||||
| -rw-r--r-- | tests/diagnostics/end-of-input.slang | 3 |
3 files changed, 8 insertions, 0 deletions
diff --git a/source/compiler-core/slang-lexer-diagnostic-defs.h b/source/compiler-core/slang-lexer-diagnostic-defs.h index ceeb62455..bce287685 100644 --- a/source/compiler-core/slang-lexer-diagnostic-defs.h +++ b/source/compiler-core/slang-lexer-diagnostic-defs.h @@ -31,5 +31,6 @@ DIAGNOSTIC(10004, Error, endOfFileInLiteral, "end of file in literal") DIAGNOSTIC(10005, Error, newlineInLiteral, "newline in literal") DIAGNOSTIC(10010, Error, quoteCannotBeDelimiter, "'\"' encountered before '(' in raw string literal. '\"' cannot be a part of a delimiter.") +DIAGNOSTIC(10011, Error, unexpectedEndOfInput, "unexpected end of input") #undef DIAGNOSTIC diff --git a/source/compiler-core/slang-lexer.cpp b/source/compiler-core/slang-lexer.cpp index 8c428159c..10c5aa1ae 100644 --- a/source/compiler-core/slang-lexer.cpp +++ b/source/compiler-core/slang-lexer.cpp @@ -1374,6 +1374,10 @@ namespace Slang char buffer[] = { (char) c, 0 }; sink->diagnose(loc, LexerDiagnostics::illegalCharacterPrint, buffer); } + else if(c == kEOF) + { + sink->diagnose(loc, LexerDiagnostics::unexpectedEndOfInput); + } else { // Fallback: print as hexadecimal diff --git a/tests/diagnostics/end-of-input.slang b/tests/diagnostics/end-of-input.slang new file mode 100644 index 000000000..ff82a91ba --- /dev/null +++ b/tests/diagnostics/end-of-input.slang @@ -0,0 +1,3 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): +// CHECK: tests/diagnostics/end-of-input.slang(3): error 10011: unexpected end of input +\ |
