From 0614e17b73b26b8371d6cc021e5c5f3abd24bb0a Mon Sep 17 00:00:00 2001 From: John Breaux Date: Mon, 5 Aug 2024 12:36:27 -0500 Subject: [PATCH] ast: Consistent constant folding. --- src/parser/ast.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/parser/ast.rs b/src/parser/ast.rs index afd1fce..b061d0f 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -645,13 +645,12 @@ pub mod canonical { Expr::Number(tail) } Expr::Binary(head, tails) => { + let mut tails = tails.into_iter().map(|(op, tail)| (op, tail.to_canonical())); let mut head = match head.to_canonical() { Expr::Number(n) => n, - head => return Expr::Binary(head.into(), tails), + head => return Expr::Binary(head.into(), tails.collect()), }; - let mut tails = tails.into_iter(); for (op, tail) in &mut tails { - let tail = tail.to_canonical(); // If the canonical tail isn't a number, rebuild and return let Expr::Number(tail) = tail else { return Expr::Binary(