fix(compiler): Correct exhaustive check on record adt with when pattern#2355
Merged
ospencer merged 4 commits intograin-lang:mainfrom Mar 28, 2026
Merged
fix(compiler): Correct exhaustive check on record adt with when pattern#2355ospencer merged 4 commits intograin-lang:mainfrom
ospencer merged 4 commits intograin-lang:mainfrom
Conversation
ospencer
reviewed
Feb 6, 2026
| @@ -2153,6 +2153,11 @@ module Conv = { | |||
| }; | |||
| Hashtbl.add(constrs, id, cstr); | |||
| switch (lst) { | |||
Member
There was a problem hiding this comment.
Let's change this to match on both the values as well as cstr_inlined, explicitly matching on the Some(_) and None cases.
In the Some case, for the constructor values, if the list is empty, we should fail. If the list contains more than one item, we should fail. We then need to handle all of the cases that are valid. Is it just Any? Feels like Or and Alias are valid here too.
Member
Author
There was a problem hiding this comment.
Instead of just handling all the casees I refactored this a tiny bit so that it's more explicit what type a constructor is.
8a179c0 to
4b98be1
Compare
ospencer
approved these changes
Mar 28, 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.
This pr corrects exhaustive checking when inlined records are mixed with when clauses, like in the example below:
Previously, we were not providing a warning, which was due to a small bug in
Conv, where we didn't propagate anyAnypattern. This handles the edge case correctly, allowing a warning to show up. However, I think we may want to take a deeper look into pattern matching semantics eventually, as theConvlogic feels fragile in general.Closes: #2311