fix: prevent Any type from shadowing type errors in match arms#761
Open
Aletheia-Prime wants to merge 1 commit intoHigherOrderCO:mainfrom
Open
fix: prevent Any type from shadowing type errors in match arms#761Aletheia-Prime wants to merge 1 commit intoHigherOrderCO:mainfrom
Aletheia-Prime wants to merge 1 commit intoHigherOrderCO:mainfrom
Conversation
When unreachable() was used in a match arm, the type checker would infer Any as the return type. Since Any can unify with anything, it would absorb type constraints from other arms, allowing invalid types to pass without error. This fix preserves type constraints from non-Any arms when the final unified type is Any but a previous arm has free type variables.
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.
Summary
When
unreachable()is used in a match arm, the type checker infersAnyas the return type. SinceAnycan unify with anything in the unification function, it absorbs type constraints from other arms, allowing invalid types to pass without error.Fix
Modified
infer_match_casesintype_check.rsto preserve the type constraints from non-Anyarms. When the final unified type isAnybut a previous arm has free type variables, we use the previous arm's type to preserve those constraints.Test
The fix was verified against the test case from issue #742:
Before fix: No type error (incorrect)
After fix: Type error as expected
All existing tests pass (20 passed, 2 ignored).