-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix match statement issue #11363
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
Merged
+52
−1
Merged
Fix match statement issue #11363
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
packages/pyright-internal/src/tests/samples/matchSequenceVariadic.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # This sample tests pattern matching with variadic tuple types. | ||
| # From the regression report for Pyright 1.1.408. | ||
|
|
||
| from typing import TypeAlias, assert_type | ||
|
|
||
| Func6Input: TypeAlias = tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int] | ||
|
|
||
|
|
||
| def func6(val: Func6Input): | ||
| match val: | ||
| case (x,): | ||
| # Type may be narrowed to tuple[int]. | ||
| # E: Argument of type "tuple[int]" cannot be assigned to parameter of type "tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]" | ||
| assert_type(val, Func6Input) | ||
| assert_type(val, tuple[int]) | ||
|
|
||
| case (x, y): | ||
| # Type may be narrowed to tuple[str, str] | tuple[int, int]. | ||
| # E: Argument of type "tuple[str, str] | tuple[int, int]" cannot be assigned to parameter of type "tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]" | ||
| assert_type(val, Func6Input) | ||
| assert_type(val, tuple[str, str] | tuple[int, int]) | ||
|
|
||
| case (x, y, z): | ||
| # Type may be narrowed to tuple[int, str, int]. | ||
| # This case should be reachable! | ||
| # E: Argument of type "tuple[int, str, int]" cannot be assigned to parameter of type "tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]" | ||
| assert_type(val, Func6Input) | ||
| assert_type(val, tuple[int, str, int]) | ||
|
|
||
| case (w, x, y, z): | ||
| # Type may be narrowed to tuple[int, str, str, int]. | ||
| # E: Argument of type "tuple[int, str, str, int]" cannot be assigned to parameter of type "tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]" | ||
| assert_type(val, Func6Input) | ||
| assert_type(val, tuple[int, str, str, int]) |
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
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.
Copilot generated:
-1442
After
tupleIndeterminateIndex = -1, the resultingSequencePatternInfowill haveisUnboundedTuple: falseeven though the original tuple IS unbounded. This works today becauseisPotentialNoMatch = trueprevents elimination beforeisUnboundedTupleis consulted, but any future consumer ofisUnboundedTuplethat trusts it as ground truth will get incorrect information. Consider:isUnboundedTuple: removedIndeterminate || tupleIndeterminateIndex >= 0at the push site (around line 1510) to preserve semantic accuracy.