[ty] fix panic when instantiating a type variable with invalid constraints#21663
Merged
carljm merged 3 commits intoastral-sh:mainfrom Dec 5, 2025
Merged
[ty] fix panic when instantiating a type variable with invalid constraints#21663carljm merged 3 commits intoastral-sh:mainfrom
carljm merged 3 commits intoastral-sh:mainfrom
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
carljm
approved these changes
Dec 5, 2025
Contributor
carljm
left a comment
There was a problem hiding this comment.
This looks good; sorry I didn't get to it sooner. Can you fix up the conflicts?
Collaborator
Author
Yes, but it would be better to merge #21802 first. |
Contributor
Done |
carljm
approved these changes
Dec 5, 2025
dcreager
added a commit
that referenced
this pull request
Dec 5, 2025
* 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 `_` ...
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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