Update #4202: Add shift operator bshl and bshr for integers (#5928)

* Update #4202: Add shift operator bshl and bshr for integers

* Add more tests
This commit is contained in:
Justin Ma
2022-07-02 19:48:43 +08:00
committed by GitHub
parent 3b357e5402
commit 3917fda7ed
8 changed files with 94 additions and 0 deletions

View File

@ -4106,6 +4106,8 @@ pub fn parse_operator(
b"in" => Operator::In,
b"not-in" => Operator::NotIn,
b"mod" => Operator::Modulo,
b"bshl" => Operator::ShiftLeft,
b"bshr" => Operator::ShiftRight,
b"starts-with" => Operator::StartsWith,
b"ends-with" => Operator::EndsWith,
b"&&" | b"and" => Operator::And,

View File

@ -492,6 +492,25 @@ pub fn math_result_type(
)
}
},
Operator::ShiftLeft | Operator::ShiftRight => 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(),
)),
)
}
},
},
_ => {
*op = Expression::garbage(op.span);