From 74ed734847a25b03ccbc3212c115fede7cc2c1dd Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Sun, 2 Jul 2023 08:59:49 +1000 Subject: [PATCH] Fix missed substitution bug --- valuescript_compiler/src/optimization/kal.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/valuescript_compiler/src/optimization/kal.rs b/valuescript_compiler/src/optimization/kal.rs index 2590c03..708a36f 100644 --- a/valuescript_compiler/src/optimization/kal.rs +++ b/valuescript_compiler/src/optimization/kal.rs @@ -641,8 +641,14 @@ impl FnState { dst: &Register, op: fn(left: &Val, right: &Val) -> Result, ) -> Option<()> { - let left = self.eval_arg(left).try_to_val()?; - let right = self.eval_arg(right).try_to_val()?; + // It's important that the eval happens on both args (left shouldn't emit None early) because + // eval_arg also substitutes the Value using knowledge + let left = self.eval_arg(left); + let right = self.eval_arg(right); + + let left = left.try_to_val()?; + let right = right.try_to_val()?; + let kal = op(&left, &right).ok()?.try_to_kal()?; self.set(dst.name.clone(), kal);