fix(diagnostics): locate import parse errors in the imported file
A parse error raised while resolving an `#import` was rendered against the ROOT file's source — the caret landed on an unrelated line (often a comment) even though the message named the correct imported file. Two compounding causes: - core.zig wired `diagnostics.import_sources` only AFTER import resolution returned, but a parse error aborts mid-resolution (before that wiring), so the renderer had no imported sources and fell back to the root file. Wire it (and seed the main-file source) BEFORE resolving. - imports.zig emitted the diagnostic at the importer's `#import` span instead of the parser's actual error offset inside the imported file, and didn't pin the diagnostic's source_file to that file. parser.zig now records `err_end` alongside `err_offset` for a proper caret width. New `DiagnosticList.addFmtInFile` renders against an explicit source file; imports.zig uses it with `importErrSpan(&p)`. Regression test: examples/1176-diagnostics-import-parse-error-location (importer + deliberately-broken companion; caret must land in the companion).
This commit is contained in:
13
examples/1176-diagnostics-import-parse-error-location.sx
Normal file
13
examples/1176-diagnostics-import-parse-error-location.sx
Normal file
@@ -0,0 +1,13 @@
|
||||
// A parse error in an IMPORTED file must be located in THAT file, not the
|
||||
// importer. Regression: `import_sources` was wired to the diagnostics only
|
||||
// AFTER import resolution finished, so a parse error raised MID-resolution
|
||||
// (which aborts before that wiring) could not resolve the imported file's
|
||||
// source — the caret fell back to the root file and landed on an unrelated
|
||||
// line. The fix wires `import_sources` before resolving and pins the
|
||||
// diagnostic's `source_file` + offset to the imported file.
|
||||
//
|
||||
// The companion's error sits several lines down (after comments) so a caret
|
||||
// mislocated against THIS importer would be unmistakable.
|
||||
#import "1176-diagnostics-import-parse-error-location/broken.sx";
|
||||
|
||||
main :: () {}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Deliberately broken: exercises import parse-error LOCATION reporting.
|
||||
// These leading comment lines push the parse error down so its line number
|
||||
// differs from the importer's — a mislocated caret would point here-or-wrong
|
||||
// instead of at the real offending token below.
|
||||
//
|
||||
broken :: 1 2;
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
error: parse error in 'examples/1176-diagnostics-import-parse-error-location/broken.sx': expected ';'
|
||||
--> examples/1176-diagnostics-import-parse-error-location/broken.sx:6:13
|
||||
|
|
||||
6 | broken :: 1 2;
|
||||
| ^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user