Clarify nonexhaustive match diagnostics

This commit is contained in:
sanjin 2026-05-22 13:06:27 +02:00
parent cda20bc895
commit 4ba0a24b14
5 changed files with 20 additions and 9 deletions

View File

@ -10,10 +10,12 @@ without changing the typed core or claiming new syntax stability.
- Improve project/workspace build and run entry diagnostics.
- Keep the accepted entry contract unchanged: `(fn main () -> i32 ...)`.
- Use precise diagnostic codes for missing and invalid entry `main` functions.
- Make non-exhaustive `match` diagnostics clearer and deterministic.
## Acceptance Gates
- `cargo test --test project_mode entry_main`
- `cargo test --test diagnostics_contract`
- `cargo fmt --check`
- `git diff --check`

View File

@ -3690,10 +3690,18 @@ fn validate_match_arm_set(
.collect::<Vec<_>>();
if !missing.is_empty() {
let found = required
.iter()
.filter(|pattern| seen.contains_key(*pattern))
.map(lower::match_pattern_name)
.collect::<Vec<_>>();
return Err(Diagnostic::new(
file,
"NonExhaustiveMatch",
format!("match is missing `{}` arm(s)", missing.join("`, `")),
format!(
"match is missing required arm(s): `{}`",
missing.join("`, `")
),
)
.with_span(span)
.expected(
@ -3703,12 +3711,11 @@ fn validate_match_arm_set(
.collect::<Vec<_>>()
.join(" and "),
)
.found(
seen.keys()
.map(lower::match_pattern_name)
.collect::<Vec<_>>()
.join(", "),
));
.found(if found.is_empty() {
"no valid arms".to_string()
} else {
found.join(", ")
}));
}
Ok(())

View File

@ -15,6 +15,8 @@ integration/readiness release, not the first real beta.
`WorkspaceEntryMainMissing`, and `WorkspaceEntryMainInvalidSignature`.
Messages now spell out the required `(fn main () -> i32 ...)` contract and
include the found parameter count and return type for invalid signatures.
- Non-exhaustive `match` diagnostics now use clearer missing-arm wording and a
deterministic found-arm list.
## 1.0.0-beta.3

View File

@ -3,7 +3,7 @@
(version 1)
(severity error)
(code NonExhaustiveMatch)
(message "match is missing `Color.Blue` arm(s)")
(message "match is missing required arm(s): `Color.Blue`")
(file "<fixture>")
(span
(bytes 60 99)

View File

@ -3,7 +3,7 @@
(version 1)
(severity error)
(code NonExhaustiveMatch)
(message "match is missing `none` arm(s)")
(message "match is missing required arm(s): `none`")
(file "<fixture>")
(span
(bytes 57 105)