New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exhaustiveness checking for match statements #12267
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2611300
Add exhaustiveness checking
freundTech 8b44585
Improve exhaustiveness checking and add enum support
freundTech 33b1700
Remove outdated comment
freundTech f13c377
Final cleanup
freundTech 63faf94
Fix
JukkaL 5d82b79
Fix test case
JukkaL a36749a
Skip test case (testLiteralPatternEnumCustomEquals)
JukkaL e14bffb
Update test cases
JukkaL 1246bb7
Add docstrings
JukkaL a7a3ec9
Fix unreachable code after "case True"
JukkaL 1095852
Support narrowing down bool values
JukkaL d3d04f9
Fix type check
JukkaL 81bf0a0
Remove unused function
JukkaL 2969fac
Rename and restructure match statement test cases
JukkaL 8eb2dc9
Some clean-up
JukkaL 1de6aa3
More cleanup
JukkaL a79c4c2
Add failing test case
JukkaL 14fd60c
Add break/continue test case
JukkaL 4a96bca
Add test case
JukkaL e21b1ce
Add failing test case
JukkaL 0892388
Small tweaks
JukkaL 1d2a037
Remove unneeded change in subtype checking
JukkaL a2fa4ae
Address feedback
JukkaL File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1237,11 +1237,13 @@ def _is_proper_subtype(left: Type, right: Type, *, | |
class ProperSubtypeVisitor(TypeVisitor[bool]): | ||
def __init__(self, right: Type, *, | ||
ignore_promotions: bool = False, | ||
ignore_last_known_value: bool = False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nobody ever passes |
||
erase_instances: bool = False, | ||
keep_erased_types: bool = False) -> None: | ||
self.right = get_proper_type(right) | ||
self.orig_right = right | ||
self.ignore_promotions = ignore_promotions | ||
self.ignore_last_known_value = ignore_last_known_value | ||
self.erase_instances = erase_instances | ||
self.keep_erased_types = keep_erased_types | ||
self._subtype_kind = ProperSubtypeVisitor.build_subtype_kind( | ||
|
@@ -1297,6 +1299,10 @@ def visit_instance(self, left: Instance) -> bool: | |
if isinstance(right, Instance): | ||
if TypeState.is_cached_subtype_check(self._subtype_kind, left, right): | ||
return True | ||
if not self.ignore_last_known_value: | ||
if right.last_known_value is not None and \ | ||
right.last_known_value != left.last_known_value: | ||
return False | ||
if not self.ignore_promotions: | ||
for base in left.type.mro: | ||
if base._promote and self._is_proper_subtype(base._promote, right): | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
list(.items())
is more idiomatic (and probably cheaper) python