From ce35f7fa725906c7bf294454d5b1d86725047e56 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 24 Apr 2021 13:42:45 +0800 Subject: [PATCH] Fix off by one error in optimizer. --- src/optimize.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/optimize.rs b/src/optimize.rs index 941aa695..77243bbf 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -239,29 +239,18 @@ fn optimize_stmt_block( .find_map(|(i, stmt)| match stmt { stmt if !is_pure(stmt) => Some(i), - Stmt::Noop(_) | Stmt::Return(_, None, _) => None, - - Stmt::Let(e, _, _, _) - | Stmt::Const(e, _, _, _) - | Stmt::Expr(e) - | Stmt::Return(_, Some(e), _) - if e.is_constant() => + Stmt::Let(e, _, _, _) | Stmt::Const(e, _, _, _) | Stmt::Expr(e) + if !e.is_constant() => { - None + Some(i) } #[cfg(not(feature = "no_module"))] - Stmt::Import(e, _, _) if e.is_constant() => None, + Stmt::Import(e, _, _) if !e.is_constant() => Some(i), - #[cfg(not(feature = "no_module"))] - Stmt::Export(_, _) => None, - - #[cfg(not(feature = "no_closure"))] - Stmt::Share(_) => None, - - _ => Some(i), + _ => None, }) - .map_or(0, |n| statements.len() - n); + .map_or(0, |n| statements.len() - n - 1); while index < statements.len() { if preserve_result && index >= statements.len() - 1 {