Add bit operator: bit-xor (#5940)

This commit is contained in:
Justin Ma
2022-07-03 19:45:20 +08:00
committed by GitHub
parent 3a38fb94f0
commit 4e90b478b7
8 changed files with 59 additions and 20 deletions

View File

@ -4107,6 +4107,7 @@ pub fn parse_operator(
b"not-in" => Operator::NotIn,
b"mod" => Operator::Modulo,
b"bit-or" => Operator::BitOr,
b"bit-xor" => Operator::BitXor,
b"bit-and" => Operator::BitAnd,
b"bit-shl" => Operator::ShiftLeft,
b"bit-shr" => Operator::ShiftRight,

View File

@ -492,27 +492,29 @@ pub fn math_result_type(
)
}
},
Operator::ShiftLeft | Operator::ShiftRight | Operator::BitAnd | Operator::BitOr => {
match (&lhs.ty, &rhs.ty) {
(Type::Int, Type::Int) => (Type::Int, None),
Operator::ShiftLeft
| Operator::ShiftRight
| Operator::BitOr
| Operator::BitXor
| Operator::BitAnd => match (&lhs.ty, &rhs.ty) {
(Type::Int, Type::Int) => (Type::Int, None),
(Type::Any, _) => (Type::Any, None),
(_, Type::Any) => (Type::Any, None),
_ => {
*op = Expression::garbage(op.span);
(
Type::Any,
Some(ParseError::UnsupportedOperation(
op.span,
lhs.span,
lhs.ty.clone(),
rhs.span,
rhs.ty.clone(),
)),
)
}
(Type::Any, _) => (Type::Any, None),
(_, Type::Any) => (Type::Any, None),
_ => {
*op = Expression::garbage(op.span);
(
Type::Any,
Some(ParseError::UnsupportedOperation(
op.span,
lhs.span,
lhs.ty.clone(),
rhs.span,
rhs.ty.clone(),
)),
)
}
}
},
},
_ => {
*op = Expression::garbage(op.span);