diff --git a/.llm/BETA_4_LANGUAGE_USABILITY.md b/.llm/BETA_4_LANGUAGE_USABILITY.md index bd7a3ab..1c24f02 100644 --- a/.llm/BETA_4_LANGUAGE_USABILITY.md +++ b/.llm/BETA_4_LANGUAGE_USABILITY.md @@ -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` diff --git a/compiler/src/check.rs b/compiler/src/check.rs index 14f6781..3226a60 100644 --- a/compiler/src/check.rs +++ b/compiler/src/check.rs @@ -3690,10 +3690,18 @@ fn validate_match_arm_set( .collect::>(); if !missing.is_empty() { + let found = required + .iter() + .filter(|pattern| seen.contains_key(*pattern)) + .map(lower::match_pattern_name) + .collect::>(); 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::>() .join(" and "), ) - .found( - seen.keys() - .map(lower::match_pattern_name) - .collect::>() - .join(", "), - )); + .found(if found.is_empty() { + "no valid arms".to_string() + } else { + found.join(", ") + })); } Ok(()) diff --git a/docs/compiler/RELEASE_NOTES.md b/docs/compiler/RELEASE_NOTES.md index b7b6c29..71a3942 100644 --- a/docs/compiler/RELEASE_NOTES.md +++ b/docs/compiler/RELEASE_NOTES.md @@ -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 diff --git a/tests/enum-match-non-exhaustive.diag b/tests/enum-match-non-exhaustive.diag index 55a21d0..7ac7d36 100644 --- a/tests/enum-match-non-exhaustive.diag +++ b/tests/enum-match-non-exhaustive.diag @@ -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 "") (span (bytes 60 99) diff --git a/tests/non-exhaustive-match.diag b/tests/non-exhaustive-match.diag index bcee2a9..b3b387d 100644 --- a/tests/non-exhaustive-match.diag +++ b/tests/non-exhaustive-match.diag @@ -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 "") (span (bytes 57 105)