[ty] Add missing bitwise-operator branches for boolean and integer arithmetic (#17949)

This commit is contained in:
Alex Waygood 2025-05-08 14:10:35 +01:00 committed by GitHub
parent aac862822f
commit 67cd94ed64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View file

@ -5773,6 +5773,18 @@ impl<'db> TypeInferenceBuilder<'db> {
}
}),
(Type::IntLiteral(n), Type::IntLiteral(m), ast::Operator::BitOr) => {
Some(Type::IntLiteral(n | m))
}
(Type::IntLiteral(n), Type::IntLiteral(m), ast::Operator::BitAnd) => {
Some(Type::IntLiteral(n & m))
}
(Type::IntLiteral(n), Type::IntLiteral(m), ast::Operator::BitXor) => {
Some(Type::IntLiteral(n ^ m))
}
(Type::BytesLiteral(lhs), Type::BytesLiteral(rhs), ast::Operator::Add) => {
let bytes = [&**lhs.value(self.db()), &**rhs.value(self.db())].concat();
Some(Type::bytes_literal(self.db(), &bytes))
@ -5828,6 +5840,14 @@ impl<'db> TypeInferenceBuilder<'db> {
Some(Type::BooleanLiteral(b1 | b2))
}
(Type::BooleanLiteral(b1), Type::BooleanLiteral(b2), ast::Operator::BitAnd) => {
Some(Type::BooleanLiteral(b1 & b2))
}
(Type::BooleanLiteral(b1), Type::BooleanLiteral(b2), ast::Operator::BitXor) => {
Some(Type::BooleanLiteral(b1 ^ b2))
}
(Type::BooleanLiteral(bool_value), right, op) => self.infer_binary_expression_type(
node,
emitted_division_by_zero_diagnostic,