when two operators have the same precedence, evaluate the leftmost first

This commit is contained in:
Connor Skees 2020-07-03 20:15:00 -04:00
parent 30a3a46b2d
commit ca2938f04c
3 changed files with 7 additions and 2 deletions

View File

@ -68,7 +68,7 @@ impl<'a, 'b: 'a> ValueVisitor<'a, 'b> {
let val2 = self.paren_or_unary(val2)?; let val2 = self.paren_or_unary(val2)?;
if let HigherIntermediateValue::BinaryOp(val1_1, op2, val1_2) = val1 { if let HigherIntermediateValue::BinaryOp(val1_1, op2, val1_2) = val1 {
if op2.precedence() > op.precedence() { if op2.precedence() >= op.precedence() {
val1 = HigherIntermediateValue::Literal(self.bin_op(*val1_1, op2, *val1_2)?); val1 = HigherIntermediateValue::Literal(self.bin_op(*val1_1, op2, *val1_2)?);
} else { } else {
let val2 = HigherIntermediateValue::Literal(self.bin_op(*val1_2, op, val2)?); let val2 = HigherIntermediateValue::Literal(self.bin_op(*val1_2, op, val2)?);

View File

@ -90,7 +90,7 @@ test!(
test!( test!(
max_evaluated_binop, max_evaluated_binop,
"a {\n color: max(100% - lightness(red) - 2%);\n}\n", "a {\n color: max(100% - lightness(red) - 2%);\n}\n",
"a {\n color: 52%;\n}\n" "a {\n color: 48%;\n}\n"
); );
error!( error!(
max_arg_of_incorrect_type, max_arg_of_incorrect_type,

View File

@ -38,3 +38,8 @@ test!(
"a {\n color: a or b !=c;\n}\n", "a {\n color: a or b !=c;\n}\n",
"a {\n color: a;\n}\n" "a {\n color: a;\n}\n"
); );
test!(
leftmost_is_evaluated_first_when_same_precedence,
"a {\n color: 1 / 2 * 1em;\n}\n",
"a {\n color: 0.5em;\n}\n"
);