fix(frontend): point unmatched end diagnostics at the end payload
A stray end after an earlier statement was reported with the span of the previous payload (position-1) and a confusing 'ends outside its owning function segment' message. Report it on the end payload itself with the standard sem.unmatched_end wording, and pin the span with a unit test. Verified: clippy -D warnings clean and cargo test --workspace --locked green (62 targets).
This commit is contained in:
1 parent
9fb97bc2df
commit
a3f9770761
2 files changed
+22
-2
No files matched your search
@@ -141,10 +141,13 @@ impl Mapper {
|
||||
let mut position = 0;
|
||||
let (stmts, stop) = self.sequence(&raw, &mut position, false, false);
|
||||
if stop != Stop::Eof {
|
||||
// `sequence` leaves `position` on the stray `end` payload, so the
|
||||
// diagnostic points at the keyword instead of the previous
|
||||
// statement. A control frame may never close across a heading.
|
||||
self.error(
|
||||
codes::SEM_UNMATCHED_END,
|
||||
raw.get(position.saturating_sub(1)).map(|node| node.span),
|
||||
"control frame ends outside its owning function segment",
|
||||
raw.get(position).map(|node| node.span),
|
||||
"`end` has no open `if`/`while` in this heading segment",
|
||||
);
|
||||
}
|
||||
stmts
|
||||
|
||||
Reference in new issue
Block a user