Fix early exit for OR expression (#1738)

This commit is contained in:
Josipmrden 2024-03-11 22:44:15 +01:00 committed by GitHub
parent 1c71d605ff
commit 462336ff78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -226,7 +226,6 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
} \
}
BINARY_OPERATOR_VISITOR(OrOperator, ||, OR);
BINARY_OPERATOR_VISITOR(XorOperator, ^, XOR);
BINARY_OPERATOR_VISITOR(AdditionOperator, +, +);
BINARY_OPERATOR_VISITOR(SubtractionOperator, -, -);
@ -261,6 +260,20 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
}
}
TypedValue Visit(OrOperator &op) override {
auto value1 = op.expression1_->Accept(*this);
if (value1.IsBool() && value1.ValueBool()) {
// If first expression is true, don't evaluate the second one.
return value1;
}
auto value2 = op.expression2_->Accept(*this);
try {
return value1 || value2;
} catch (const TypedValueException &) {
throw QueryRuntimeException("Invalid types: {} and {} for OR.", value1.type(), value2.type());
}
}
TypedValue Visit(IfOperator &if_operator) override {
auto condition = if_operator.condition_->Accept(*this);
if (condition.IsNull()) {