Compare commits

...

1 Commits

Author SHA1 Message Date
Charlie Marsh
fd02fb9c76 [ty] Infer subscript types through aliases 2026-01-05 09:37:40 -05:00
2 changed files with 26 additions and 0 deletions

View File

@@ -172,6 +172,25 @@ def _(x: X, y: tuple[Literal[1], Literal[3]]):
reveal_type(x < y) # revealed: Literal[True]
```
## In subscripts
Subscript operations should work through type aliases.
```py
class C:
def __getitem__(self, index: int) -> int:
return 1
class D:
def __getitem__(self, index: int) -> int:
return 1
type CD = C | D
def _(x: CD):
reveal_type(x[1]) # revealed: int
```
## `TypeAliasType` properties
Two `TypeAliasType`s are distinct and disjoint, even if they refer to the same type

View File

@@ -12368,6 +12368,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
Some(todo_type!("Subscript expressions on intersections"))
}
(Type::TypeAlias(alias), _) => Some(self.infer_subscript_expression_types(
subscript,
alias.value_type(db),
slice_ty,
expr_context,
)),
// Ex) Given `("a", "b", "c", "d")[1]`, return `"b"`
(Type::NominalInstance(nominal), Type::IntLiteral(i64_int)) => nominal
.tuple_spec(db)