Fix panic for illegal Literal[…] annotations with inner subscript expressions (#19489)

## Summary

Fixes pull-types panics for illegal annotations like
`Literal[object[index]]`.

Originally reported by @AlexWaygood

## Test Plan

* Verified that this caused panics in the playground, when typing (and
potentially hovering over) `x: Literal[obj[0]]`.
* Added a regression test
This commit is contained in:
David Peter 2025-07-22 16:07:20 +02:00 committed by GitHub
parent fd335eb8b7
commit ee69d38000
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View file

@ -60,6 +60,10 @@ class NotAnEnum:
# error: [invalid-type-form]
invalid5: Literal[NotAnEnum.x]
a_list: list[int] = [1, 2, 3]
# error: [invalid-type-form]
invalid6: Literal[a_list[0]]
```
## Shortening unions of literals

View file

@ -10438,6 +10438,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
self.store_expression_type(parameters, ty);
ty
} else {
self.infer_expression(slice);
self.store_expression_type(parameters, Type::unknown());
return Err(vec![parameters]);