Clarify nonexhaustive match diagnostics
This commit is contained in:
parent
cda20bc895
commit
4ba0a24b14
@ -10,10 +10,12 @@ without changing the typed core or claiming new syntax stability.
|
|||||||
- Improve project/workspace build and run entry diagnostics.
|
- Improve project/workspace build and run entry diagnostics.
|
||||||
- Keep the accepted entry contract unchanged: `(fn main () -> i32 ...)`.
|
- Keep the accepted entry contract unchanged: `(fn main () -> i32 ...)`.
|
||||||
- Use precise diagnostic codes for missing and invalid entry `main` functions.
|
- Use precise diagnostic codes for missing and invalid entry `main` functions.
|
||||||
|
- Make non-exhaustive `match` diagnostics clearer and deterministic.
|
||||||
|
|
||||||
## Acceptance Gates
|
## Acceptance Gates
|
||||||
|
|
||||||
- `cargo test --test project_mode entry_main`
|
- `cargo test --test project_mode entry_main`
|
||||||
|
- `cargo test --test diagnostics_contract`
|
||||||
- `cargo fmt --check`
|
- `cargo fmt --check`
|
||||||
- `git diff --check`
|
- `git diff --check`
|
||||||
|
|
||||||
|
|||||||
@ -3690,10 +3690,18 @@ fn validate_match_arm_set(
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if !missing.is_empty() {
|
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(
|
return Err(Diagnostic::new(
|
||||||
file,
|
file,
|
||||||
"NonExhaustiveMatch",
|
"NonExhaustiveMatch",
|
||||||
format!("match is missing `{}` arm(s)", missing.join("`, `")),
|
format!(
|
||||||
|
"match is missing required arm(s): `{}`",
|
||||||
|
missing.join("`, `")
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.with_span(span)
|
.with_span(span)
|
||||||
.expected(
|
.expected(
|
||||||
@ -3703,12 +3711,11 @@ fn validate_match_arm_set(
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" and "),
|
.join(" and "),
|
||||||
)
|
)
|
||||||
.found(
|
.found(if found.is_empty() {
|
||||||
seen.keys()
|
"no valid arms".to_string()
|
||||||
.map(lower::match_pattern_name)
|
} else {
|
||||||
.collect::<Vec<_>>()
|
found.join(", ")
|
||||||
.join(", "),
|
}));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -15,6 +15,8 @@ integration/readiness release, not the first real beta.
|
|||||||
`WorkspaceEntryMainMissing`, and `WorkspaceEntryMainInvalidSignature`.
|
`WorkspaceEntryMainMissing`, and `WorkspaceEntryMainInvalidSignature`.
|
||||||
Messages now spell out the required `(fn main () -> i32 ...)` contract and
|
Messages now spell out the required `(fn main () -> i32 ...)` contract and
|
||||||
include the found parameter count and return type for invalid signatures.
|
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
|
## 1.0.0-beta.3
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
(version 1)
|
(version 1)
|
||||||
(severity error)
|
(severity error)
|
||||||
(code NonExhaustiveMatch)
|
(code NonExhaustiveMatch)
|
||||||
(message "match is missing `Color.Blue` arm(s)")
|
(message "match is missing required arm(s): `Color.Blue`")
|
||||||
(file "<fixture>")
|
(file "<fixture>")
|
||||||
(span
|
(span
|
||||||
(bytes 60 99)
|
(bytes 60 99)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
(version 1)
|
(version 1)
|
||||||
(severity error)
|
(severity error)
|
||||||
(code NonExhaustiveMatch)
|
(code NonExhaustiveMatch)
|
||||||
(message "match is missing `none` arm(s)")
|
(message "match is missing required arm(s): `none`")
|
||||||
(file "<fixture>")
|
(file "<fixture>")
|
||||||
(span
|
(span
|
||||||
(bytes 57 105)
|
(bytes 57 105)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user