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:
cflmy committed 2026-11-21 15:50:46 +08:00
1 parent 9fb97bc2df
commit a3f9770761
2 files changed
+22 -2

No files matched your search

+17
View File
@@ -270,6 +270,23 @@ mod tests {
assert_eq!(function.params[0].name, "x");
}
#[test]
fn unmatched_end_points_at_the_end_payload() {
let source = "## @exec f\n\n`x = 1`\n\n`end`\n";
let result = analyze(source);
let diagnostic = result
.diagnostics
.iter()
.find(|diagnostic| diagnostic.code == "sem.unmatched_end")
.expect("sem.unmatched_end");
let span = diagnostic.span.expect("span");
assert_eq!(
&source[span.start..span.end],
"`end`",
"the diagnostic must point at the stray end payload"
);
}
#[test]
fn invalid_strong_payload_is_a_hard_error() {
let result = analyze("## @exec f\n\n**a *b* c**\n");