1
0
Fork 0

Fix if-then interpreting to align with language spec

This commit is contained in:
Vili Sinervä 2025-02-04 15:21:04 +02:00
parent 958957e6dd
commit c92ff6140e
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996

View file

@ -81,16 +81,21 @@ pub fn interpret<'source>(ast: &Expression<'source>, symbols: &mut SymTab<'sourc
Value::None()
}
Conditional(_, condition_expr, then_expr, else_expr) => {
if let Value::Bool(condition) = interpret(condition_expr, symbols) {
let Value::Bool(condition) = interpret(condition_expr, symbols) else {
panic!("Non-bool as if-then-else condition!");
};
if let Some(else_expr) = else_expr {
if condition {
interpret(then_expr, symbols)
} else if let Some(expr) = else_expr {
interpret(expr, symbols)
} else {
Value::None()
interpret(else_expr, symbols)
}
} else {
panic!("Non-bool as if-then-else condition!");
if condition {
interpret(then_expr, symbols);
}
Value::None()
}
}
While(_, condition, do_expr) => {