-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug that results in an incorrect type evaluation when a
match
…
… statement uses a pattern with a target expression that overwrites the subject expression. This addresses #9418. (#9428)
- Loading branch information
Showing
4 changed files
with
73 additions
and
2 deletions.
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
34 changes: 34 additions & 0 deletions
34
packages/pyright-internal/src/tests/samples/matchClass7.py
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This sample tests the case where a class pattern overwrites the subject | ||
# expression. | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class DC1: | ||
val: str | ||
|
||
|
||
def func1(val: DC1): | ||
result = val | ||
|
||
match result: | ||
case DC1(result): | ||
reveal_type(result, expected_text="str") | ||
|
||
|
||
@dataclass | ||
class DC2: | ||
val: DC1 | ||
|
||
|
||
def func2(val: DC2): | ||
result = val | ||
|
||
match result.val: | ||
case DC1(result): | ||
reveal_type(result, expected_text="str") | ||
|
||
# This should generate an error because result.val | ||
# is no longer valid at this point. | ||
print(result.val) |
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