-
Notifications
You must be signed in to change notification settings - Fork 167
Labels
contextual-typingissues related to contextual typingissues related to contextual typing
Milestone
Description
Describe the Bug
I was surprised to not see an issue for this yet (unless I just missed it?). Opening one for V1 tracking. Contextual typing doesn't play well with union types, as seen here:
pyrefly/pyrefly/lib/test/contextual.rs
Lines 104 to 116 in 2520a37
| testcase!( | |
| bug = "Both assignments should be allowed. When decomposing the contextual hint, we eagerly resolve vars to the 'first' branch of the union. Note: due to the union's sorted representation, the first branch is not necessarily the first in source order.", | |
| test_contextual_typing_against_unions, | |
| r#" | |
| class A: ... | |
| class B: ... | |
| class B2(B): ... | |
| class C: ... | |
| x: list[A] | list[B] = [B2()] # E: `list[B2]` is not assignable to `list[A] | list[B]` | |
| y: list[B] | list[C] = [B2()] | |
| "#, | |
| ); |
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
No response
Metadata
Metadata
Assignees
Labels
contextual-typingissues related to contextual typingissues related to contextual typing