mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 00:20:22 +00:00
[ty] Add missing bitwise-operator branches for boolean and integer arithmetic (#17949)
This commit is contained in:
parent
aac862822f
commit
67cd94ed64
3 changed files with 35 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue