Skip to content

Commit

Permalink
Fix missed substitution bug
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 1, 2023
1 parent edecfee commit 74ed734
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions valuescript_compiler/src/optimization/kal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,14 @@ impl FnState {
dst: &Register,
op: fn(left: &Val, right: &Val) -> Result<Val, Val>,
) -> 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);
Expand Down

0 comments on commit 74ed734

Please sign in to comment.