From 35061af11bf13f0b28dfbeb69c9c1274fad9d544 Mon Sep 17 00:00:00 2001 From: kalsprite Date: Sun, 16 Aug 2026 17:31:59 -0700 Subject: [PATCH] fix eol diagnostic --- src/error.cpp | 6 ++++-- src/parser.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/error.cpp b/src/error.cpp index 53bc01654..ee2d79c27 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -432,8 +432,10 @@ gb_internal isize show_error_on_line(TokenPos const &pos, TokenPos end) { window_close_bytes = line_length_bytes; } - for (i32 i = error_start_index_graphemes; i > 0; i -= 1) { - if (graphemes[i].byte_index == window_open_bytes) { + // counts the graphemes before the error. It must not read the one at it: an error at the + // end of a line indexes one past the last grapheme + for (i32 i = error_start_index_graphemes-1; i >= 0; i -= 1) { + if (graphemes[i].byte_index < window_open_bytes) { break; } squiggle_padding += graphemes[i].width; diff --git a/src/parser.cpp b/src/parser.cpp index d981491dd..f8d5cb1b8 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -113,6 +113,12 @@ gb_internal gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_) if (len < offset) { return nullptr; } + + // a column past the first cannot belong to a line the offset has already left + if (offset > 0 && pos.column > 1 && start[offset-1] == '\n') { + offset -= 1; + } + u8 *pos_offset = start+offset; u8 *line_start = pos_offset;