-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] fix panic when instantiating a type variable with invalid constraints #21663
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
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
carljm
left a comment
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 looks good; sorry I didn't get to it sooner. Can you fix up the conflicts?
Yes, but it would be better to merge #21802 first. |
Done |
* origin/main: (41 commits) [ty] Carry generic context through when converting class into `Callable` (#21798) [ty] Add more tests for renamings (#21810) [ty] Minor improvements to `assert_type` diagnostics (#21811) [ty] Add some attribute/method renaming test cases (#21809) Update mkdocs-material to 9.7.0 (Insiders now free) (#21797) Remove unused whitespaces in test cases (#21806) [ty] fix panic when instantiating a type variable with invalid constraints (#21663) [ty] fix build failure caused by conflicts between #21683 and #21800 (#21802) [ty] do nothing with `store_expression_type` if `inner_expression_inference_state` is `Get` (#21718) [ty] increase the limit on the number of elements in a non-recursively defined literal union (#21683) [ty] normalize typevar bounds/constraints in cycles (#21800) [ty] Update completion eval to include modules [ty] Add modules to auto-import [ty] Add support for module-only import requests [ty] Refactor auto-import symbol info [ty] Clarify the use of `SymbolKind` in auto-import [ty] Redact ranking of completions from e2e LSP tests [ty] Tweaks tests to use clearer language [ty] Update evaluation results [ty] Make auto-import ignore symbols in modules starting with a `_` ...
Summary
This PR fixes a panic that occurs with code like this:
The panic occurs because the constraints of
Tare inferred to beUnknown | Unknown.Calling
to_instanceon such a type results inUnknown, but the panic occurs because contexts expecting constraints on type variables only accept union types.A fundamental solution to this problem would be to define a new struct
TypeVarConstraintsto hold each constraint individually, rather than trying to store everything in aUnionType. There may be additional cost for converting between this and a union type. I'll ask codspeed if this is actually costly.Panic log
Test Plan
New corpus test