From c92ff6140e0bd46564dafffc66a206f4b208d80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vili=20Sinerv=C3=A4?= Date: Tue, 4 Feb 2025 15:21:04 +0200 Subject: [PATCH] Fix if-then interpreting to align with language spec --- src/compiler/interpreter.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler/interpreter.rs b/src/compiler/interpreter.rs index c46890e..cd4a78f 100644 --- a/src/compiler/interpreter.rs +++ b/src/compiler/interpreter.rs @@ -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) => {