!= defaults to true for different parameter types.

This commit is contained in:
Stephen Chung 2020-05-30 13:49:40 +08:00
parent 4c46c7e26b
commit acd0f6b56b

View File

@ -1762,37 +1762,34 @@ fn parse_binary_op<'a>(
let cmp_def = Some(false.into()); let cmp_def = Some(false.into());
let op = op_token.syntax(); let op = op_token.syntax();
let hash = calc_fn_hash(empty(), &op, 2, empty()); let hash = calc_fn_hash(empty(), &op, 2, empty());
let op = (op, true, pos);
let mut args = StaticVec::new(); let mut args = StaticVec::new();
args.push(root); args.push(root);
args.push(rhs); args.push(rhs);
root = match op_token { root = match op_token {
Token::Plus => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))), Token::Plus
Token::Minus => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))), | Token::Minus
Token::Multiply => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))), | Token::Multiply
Token::Divide => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))), | Token::Divide
| Token::LeftShift
| Token::RightShift
| Token::Modulo
| Token::PowerOf
| Token::Ampersand
| Token::Pipe
| Token::XOr => Expr::FnCall(Box::new((op, None, hash, args, None))),
Token::LeftShift => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))), // '!=' defaults to true when passed invalid operands
Token::RightShift => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))), Token::NotEqualsTo => Expr::FnCall(Box::new((op, None, hash, args, Some(true.into())))),
Token::Modulo => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))),
Token::PowerOf => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))),
// Comparison operators default to false when passed invalid operands // Comparison operators default to false when passed invalid operands
Token::EqualsTo => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, cmp_def))), Token::EqualsTo
Token::NotEqualsTo => { | Token::LessThan
Expr::FnCall(Box::new(((op, true, pos), None, hash, args, cmp_def))) | Token::LessThanEqualsTo
} | Token::GreaterThan
Token::LessThan => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, cmp_def))), | Token::GreaterThanEqualsTo => Expr::FnCall(Box::new((op, None, hash, args, cmp_def))),
Token::LessThanEqualsTo => {
Expr::FnCall(Box::new(((op, true, pos), None, hash, args, cmp_def)))
}
Token::GreaterThan => {
Expr::FnCall(Box::new(((op, true, pos), None, hash, args, cmp_def)))
}
Token::GreaterThanEqualsTo => {
Expr::FnCall(Box::new(((op, true, pos), None, hash, args, cmp_def)))
}
Token::Or => { Token::Or => {
let rhs = args.pop(); let rhs = args.pop();
@ -1804,10 +1801,6 @@ fn parse_binary_op<'a>(
let current_lhs = args.pop(); let current_lhs = args.pop();
Expr::And(Box::new((current_lhs, rhs, pos))) Expr::And(Box::new((current_lhs, rhs, pos)))
} }
Token::Ampersand => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))),
Token::Pipe => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))),
Token::XOr => Expr::FnCall(Box::new(((op, true, pos), None, hash, args, None))),
Token::In => { Token::In => {
let rhs = args.pop(); let rhs = args.pop();
let current_lhs = args.pop(); let current_lhs = args.pop();