Skip to content

Commit 8ce7a7b

Browse files
antonsyndclaude
andcommitted
fix(compiler): add diagnostic explanations for SPY0026 and SPY0027
Add DiagnosticExplanation entries for the two new byte string diagnostic codes (UnterminatedByteString, UnicodeEscapeInByteString) added in the byte literal lexer support. Update active code count comment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 58597fc commit 8ce7a7b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Sharpy.Compiler/Diagnostics/DiagnosticCodes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public static class DiagnosticCodes
2424
{
2525
/// <summary>
2626
/// Lexer diagnostic codes (SPY0001-SPY0099).
27-
/// Active: SPY0001-SPY0025 (25 codes)
28-
/// Reserved: SPY0026-SPY0099 (74 codes for future lexer diagnostics)
27+
/// Active: SPY0001-SPY0027 (27 codes)
28+
/// Reserved: SPY0028-SPY0099 (72 codes for future lexer diagnostics)
2929
/// </summary>
3030
public static class Lexer
3131
{

src/Sharpy.Compiler/Diagnostics/DiagnosticExplanations.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ private static Dictionary<string, DiagnosticExplanation> BuildExplanations()
167167
"import `System.IO`",
168168
"Split into separate backtick segments:\n import `System`.IO");
169169

170+
Add(dict, DiagnosticCodes.Lexer.UnterminatedByteString, "Unterminated byte string literal", "Lexer",
171+
"A byte string literal was opened with b\" or b' but never closed. The lexer reached the end of the line or file without finding a matching closing quote.",
172+
"data: bytes = b\"hello",
173+
"Add the closing quote:\n data: bytes = b\"hello\"");
174+
175+
Add(dict, DiagnosticCodes.Lexer.UnicodeEscapeInByteString, "Unicode escape in byte string", "Lexer",
176+
"A byte string literal contains a \\u or \\U unicode escape sequence, which is not allowed. Byte strings can only contain values in the 0-255 range. Use \\x escapes for hex byte values instead.",
177+
"data: bytes = b\"\\u0041\"",
178+
"Use a hex escape instead:\n data: bytes = b\"\\x41\"");
179+
170180
// ── Parser errors (SPY0100-SPY0199) ─────────────────────────────
171181

172182
Add(dict, DiagnosticCodes.Parser.UnexpectedToken, "Unexpected token", "Parser",

0 commit comments

Comments
 (0)