mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
[red-knot] Fix intersection simplification for ~Any
/~Unknown
(#14195)
## Summary Another bug found using [property testing](https://github.com/astral-sh/ruff/pull/14178). ## Test Plan New unit test
This commit is contained in:
parent
fed35a25e8
commit
670f958525
1 changed files with 17 additions and 1 deletions
|
@ -317,7 +317,7 @@ impl<'db> InnerIntersectionBuilder<'db> {
|
||||||
// Adding any of these types to the negative side of an intersection
|
// Adding any of these types to the negative side of an intersection
|
||||||
// is equivalent to adding it to the positive side. We do this to
|
// is equivalent to adding it to the positive side. We do this to
|
||||||
// simplify the representation.
|
// simplify the representation.
|
||||||
self.positive.insert(ty);
|
self.add_positive(db, ty);
|
||||||
}
|
}
|
||||||
// ~Literal[True] & bool = Literal[False]
|
// ~Literal[True] & bool = Literal[False]
|
||||||
Type::BooleanLiteral(bool)
|
Type::BooleanLiteral(bool)
|
||||||
|
@ -592,6 +592,22 @@ mod tests {
|
||||||
assert_eq!(ta_not_i0.display(&db).to_string(), "int & Any | Literal[1]");
|
assert_eq!(ta_not_i0.display(&db).to_string(), "int & Any | Literal[1]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn build_intersection_simplify_negative_any() {
|
||||||
|
let db = setup_db();
|
||||||
|
|
||||||
|
let ty = IntersectionBuilder::new(&db)
|
||||||
|
.add_negative(Type::Any)
|
||||||
|
.build();
|
||||||
|
assert_eq!(ty, Type::Any);
|
||||||
|
|
||||||
|
let ty = IntersectionBuilder::new(&db)
|
||||||
|
.add_positive(Type::Never)
|
||||||
|
.add_negative(Type::Any)
|
||||||
|
.build();
|
||||||
|
assert_eq!(ty, Type::Never);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn intersection_distributes_over_union() {
|
fn intersection_distributes_over_union() {
|
||||||
let db = setup_db();
|
let db = setup_db();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue