-
Notifications
You must be signed in to change notification settings - Fork 177
fix preserve Literal through generic function calls #1468
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
base: main
Are you sure you want to change the base?
Conversation
| drop(v2_ref); | ||
| drop(variables); | ||
| self.is_subset_eq(t1, &t2) | ||
| match self.is_subset_eq(t1, &t2) { |
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.
(same thing here - I don't think we would ever want to change an answer after it has been decided already)
| drop(v1_ref); | ||
| drop(variables); | ||
| self.is_subset_eq(&t1, t2) | ||
| match self.is_subset_eq(&t1, t2) { |
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.
This section looks unsafe to me, I don't see how it could be okay to change an Answer after it's already been decided.
Do you remember why this was needed? It may be a hint that propagating literals isn't going to work well at least at this time.
|
The core part of the change in But that issue is controversial, I'm not convinced this is a good idea for two reasons:
I believe the discussion of #1138 also suggested that we might also have to promote sometimes depending on variance to make this work well because, for example if I'm curious what @samwgoldman thinks, I'd also be curious to hear more about why the lines rewriting |
fix #1138
Preserved literal instantiations for quantified type variables, so generic calls now keep Literal[...] precision. Let quantified variables keep their precise literal answer only until a later constraint rejects it, then automatically widen to the promoted class type so multi-argument inference succeeds without regressing literal-preserving cases
stores the literal answer first, only promoting to the base type when the literal fails its bound, and continues to record specialization errors if both literal and promoted forms violate the bound.
After TypedDict construction, promote inferred type arguments from literals to their general class types so C(x=0) now infers C[int] instead of C[Literal[0]]