Skip to content

Commit

Permalink
bool and int are not disjoint
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Oct 18, 2024
1 parent 3d4bd52 commit e5af7c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ impl<'db> Type<'db> {
}
}

(Type::BooleanLiteral(bool_value), Type::IntLiteral(int_value))
| (Type::IntLiteral(int_value), Type::BooleanLiteral(bool_value)) => {
i64::from(bool_value) != int_value
}

(
left @ (Type::None
| Type::BooleanLiteral(..)
Expand Down Expand Up @@ -534,7 +539,7 @@ impl<'db> Type<'db> {
(Type::BooleanLiteral(..), Type::Instance(class_type))
| (Type::Instance(class_type), Type::BooleanLiteral(..)) => !matches!(
class_type.known(db),
Some(KnownClass::Bool | KnownClass::Object)
Some(KnownClass::Bool | KnownClass::Int | KnownClass::Object)
),
(Type::BooleanLiteral(..), _) | (_, Type::BooleanLiteral(..)) => true,

Expand Down Expand Up @@ -1852,9 +1857,10 @@ mod tests {
#[test_case(Ty::None, Ty::LiteralString)]
#[test_case(Ty::None, Ty::BuiltinInstance("int"))]
#[test_case(Ty::None, Ty::Tuple(vec![Ty::None]))]
#[test_case(Ty::BoolLiteral(true), Ty::BuiltinInstance("int"))]
#[test_case(Ty::BoolLiteral(true), Ty::BoolLiteral(false))]
#[test_case(Ty::BoolLiteral(true), Ty::Tuple(vec![Ty::None]))]
#[test_case(Ty::BoolLiteral(true), Ty::IntLiteral(0))]
#[test_case(Ty::BoolLiteral(false), Ty::IntLiteral(1))]
#[test_case(Ty::IntLiteral(1), Ty::IntLiteral(2))]
#[test_case(Ty::IntLiteral(1), Ty::Tuple(vec![Ty::None]))]
#[test_case(Ty::StringLiteral("a"), Ty::StringLiteral("b"))]
Expand Down Expand Up @@ -1886,6 +1892,9 @@ mod tests {
#[test_case(Ty::BoolLiteral(true), Ty::BoolLiteral(true))]
#[test_case(Ty::BoolLiteral(false), Ty::BoolLiteral(false))]
#[test_case(Ty::BoolLiteral(true), Ty::BuiltinInstance("bool"))]
#[test_case(Ty::BoolLiteral(true), Ty::BuiltinInstance("int"))]
#[test_case(Ty::BoolLiteral(true), Ty::IntLiteral(1))]
#[test_case(Ty::BoolLiteral(false), Ty::IntLiteral(0))]
#[test_case(Ty::IntLiteral(1), Ty::IntLiteral(1))]
#[test_case(Ty::StringLiteral("a"), Ty::StringLiteral("a"))]
#[test_case(Ty::StringLiteral("a"), Ty::LiteralString)]
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_python_semantic/src/types/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ mod tests {
let db = setup_db();

let t_p = KnownClass::Int.to_instance(&db);
let t_n = Type::BooleanLiteral(false);
let t_n = Type::StringLiteral(StringLiteralType::new(&db, "t_n"));

let ty = IntersectionBuilder::new(&db)
.add_positive(t_p)
Expand Down

0 comments on commit e5af7c9

Please sign in to comment.