[ty] Infer types for ty_extensions.Intersection[A, B] tuple expressions (#18321)
## Summary fixes astral-sh/ty#366 ## Test Plan * Added panic corpus regression tests * I also wrote a hover regression test (see below), but decided not to include it. The corpus tests are much more "effective" at finding these types of errors, since they exhaustively check all expressions for types. <details> ```rs #[test] fn hover_regression_test_366() { let test = cursor_test( r#" from ty_extensions import Intersection class A: ... class B: ... def _(x: Intersection[A,<CURSOR> B]): pass "#, ); assert_snapshot!(test.hover(), @r" A & B --------------------------------------------- ```text A & B ``` --------------------------------------------- info[hover]: Hovered content is --> main.py:7:31 | 5 | class B: ... 6 | 7 | def _(x: Intersection[A, B]): | ^^-^ | | | | | Cursor offset | source 8 | pass | "); } ``` </details>
This commit is contained in:
@@ -8648,11 +8648,16 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
element => Either::Right(std::iter::once(element)),
|
||||
};
|
||||
|
||||
elements
|
||||
let ty = elements
|
||||
.fold(IntersectionBuilder::new(db), |builder, element| {
|
||||
builder.add_positive(self.infer_type_expression(element))
|
||||
})
|
||||
.build()
|
||||
.build();
|
||||
|
||||
if matches!(arguments_slice, ast::Expr::Tuple(_)) {
|
||||
self.store_expression_type(arguments_slice, ty);
|
||||
}
|
||||
ty
|
||||
}
|
||||
KnownInstanceType::TypeOf => match arguments_slice {
|
||||
ast::Expr::Tuple(_) => {
|
||||
|
||||
Reference in New Issue
Block a user