kalk: Fix comprehensions breaking after encountering an error in the past

This commit is contained in:
PaddiM8 2023-07-20 20:47:54 +02:00
parent 2fea9777d6
commit 0573a1e9f4

View File

@ -779,23 +779,40 @@ fn eval_comprehension(
)); ));
if conditions.len() > 1 { if conditions.len() > 1 {
let x = eval_comprehension(context, left, &conditions[1..], &vars[1..])?; let x = eval_comprehension(context, left, &conditions[1..], &vars[1..]);
for value in x { if let Err(err) = x {
values.push(value); context.symbol_table.get_and_remove_var(&var.name);
return Err(err);
}
for value in x.unwrap() {
values.push(Ok(value));
} }
} }
let condition = eval_expr(context, condition, None)?; let condition = eval_expr(context, condition, None);
if let KalkValue::Boolean(boolean) = condition { match condition {
Ok(KalkValue::Boolean(boolean)) => {
if boolean && vars.len() == 1 { if boolean && vars.len() == 1 {
values.push(eval_expr(context, left, None)?); values.push(eval_expr(context, left, None));
} }
},
Err(err) => values.push(Err(err)),
_ => (),
} }
} }
context.symbol_table.get_and_remove_var(&var.name); context.symbol_table.get_and_remove_var(&var.name);
Ok(values) let mut unwrapped_values = Vec::new();
for value in values {
match value {
Ok(unwrapped_value) => unwrapped_values.push(unwrapped_value),
Err(err) => return Err(err),
}
}
Ok(unwrapped_values)
} }
fn eval_equation( fn eval_equation(