expr: short-circuit evaluation for |

This commit is contained in:
Zhuoxun Yang 2023-10-06 23:50:22 +08:00
parent fa2a14ccd2
commit 2c2e01205c

View file

@ -155,8 +155,24 @@ impl AstNode {
}
}
pub fn operand_values(&self) -> Result<Vec<String>, String> {
if let Self::Node { operands, .. } = self {
if let Self::Node {
operands, op_type, ..
} = self
{
let mut out = Vec::with_capacity(operands.len());
let mut operands = operands.iter();
if op_type == "|" {
if let Some(value) = operands.next() {
let value = value.evaluate()?;
out.push(value.clone());
if value_as_bool(&value) {
out.push(String::from("dummy"));
return Ok(out);
}
}
}
for operand in operands {
let value = operand.evaluate()?;
out.push(value);