Skip to content

Commit 670f958

Browse files
authored
[red-knot] Fix intersection simplification for ~Any/~Unknown (#14195)
## Summary Another bug found using [property testing](#14178). ## Test Plan New unit test
1 parent fed35a2 commit 670f958

File tree

1 file changed

+17
-1
lines changed
  • crates/red_knot_python_semantic/src/types

1 file changed

+17
-1
lines changed

crates/red_knot_python_semantic/src/types/builder.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<'db> InnerIntersectionBuilder<'db> {
317317
// Adding any of these types to the negative side of an intersection
318318
// is equivalent to adding it to the positive side. We do this to
319319
// simplify the representation.
320-
self.positive.insert(ty);
320+
self.add_positive(db, ty);
321321
}
322322
// ~Literal[True] & bool = Literal[False]
323323
Type::BooleanLiteral(bool)
@@ -592,6 +592,22 @@ mod tests {
592592
assert_eq!(ta_not_i0.display(&db).to_string(), "int & Any | Literal[1]");
593593
}
594594

595+
#[test]
596+
fn build_intersection_simplify_negative_any() {
597+
let db = setup_db();
598+
599+
let ty = IntersectionBuilder::new(&db)
600+
.add_negative(Type::Any)
601+
.build();
602+
assert_eq!(ty, Type::Any);
603+
604+
let ty = IntersectionBuilder::new(&db)
605+
.add_positive(Type::Never)
606+
.add_negative(Type::Any)
607+
.build();
608+
assert_eq!(ty, Type::Never);
609+
}
610+
595611
#[test]
596612
fn intersection_distributes_over_union() {
597613
let db = setup_db();

0 commit comments

Comments
 (0)