Repository navigation
lang: widen case branches; null when no match - #124
Merged
Merged
Conversation
Bring case in line with if: clause bodies that fail to merge now widen to a union instead of erroring, and a case with no matching clause and no else evaluates to null instead of raising at runtime, making the result type nullable. Type patterns covering every member of a non-null union (or an interface catch-all pattern) are recognized as exhaustive, so such cases keep a non-null result without an else. The old no-match and clause-mismatch error tests now describe valid programs; they are replaced by test_case_widen_nullable.dang plus an error test pinning the nullable taint diagnostic when a non-exhaustive case flows into a non-null return type. Signed-off-by: Alex Suraci <[email protected]>
Update /control-flow for the new case semantics: diverging clause bodies widen to a union like if branches, an unmatched case yields null (nullable result type), and exhaustive type-pattern coverage of a non-null union keeps the result non-null without an else. Adjust the union-discrimination notes on /interfaces-unions and the dang-language skill references to match. Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
103cd1b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://02bb3baf.dang-3kk.pages.dev |
| Branch Preview URL: | https://case-widen-nullable.dang-3kk.pages.dev |
This was referenced Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses docs feedback on
/control-flow:caseshould be consistent withif— widen on branch mismatch instead of erroring, and go nullable instead of raising at runtime when nothing matches.Language changes
casenow infers an inline union (String! | Int!), exactly like divergingif/elsebranches.nullinstead of a runtime error. Acasewith no matching clause and noelseevaluates tonull, so its result type is nullable — you're forced to add anelse(or cover every possibility) to avoid the nullable taint.caseexhaustive: noelseneeded, result stays non-null. An interface operand is exhaustive only via an interface catch-all pattern (its implementer set is open); a nullable operand is never exhaustive, sincenullmatches no type pattern.try/catchis untouched: an uncaught error re-raises rather than falling through, so there's no equivalent fallthrough to make nullable.Tests
tests/errors/case_no_match.dangandcase_type_mismatch.dangnow describe valid programs and are removed, replaced bytests/test_case_widen_nullable.dangcovering widening, null fallthrough, union/inline-union/interface exhaustiveness, and the nullable-operand rule.case_nonexhaustive_nonnull.dangpins the diagnostic when a non-exhaustivecaseflows into a non-null return type.Docs
/control-flowis rewritten for the new semantics (the literate build bakes the newnulland widened results), and the union-discrimination notes on/interfaces-unionsplus thedang-languageskill references are updated to match.🤖 Generated with Claude Code