From 9fde38a6f82106e4c3a47f1bc34343650d8aad5b Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Mon, 28 Feb 2022 14:22:49 +0100 Subject: [PATCH] CR: I've a feeling we're not in Review anymore. --- src/eval/func.rs | 3 +-- src/eval/mod.rs | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/eval/func.rs b/src/eval/func.rs index b870fd9d6..a7f2a209c 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -139,8 +139,7 @@ impl Closure { // Evaluate the body. let value = match self.body.eval(ctx, &mut scp) { - Ok(value) => value, - Err(Control::Return(value, _)) => return Ok(value.unwrap_or_default()), + Err(Control::Return(value, _)) => value.unwrap_or_default(), other => other?, }; diff --git a/src/eval/mod.rs b/src/eval/mod.rs index cb80968c7..3686d665e 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -58,9 +58,13 @@ pub type EvalResult = Result; /// A control flow event that occurred during evaluation. #[derive(Clone, Debug, PartialEq)] pub enum Control { + /// Stop iteration in a loop. Break(Span), + /// Skip the remainder of the current iteration in a loop. Continue(Span), + /// Stop execution of a function early, optionally returning a value. Return(Option, Span), + /// Stop the execution because an error occurred. Err(TypError), } @@ -634,7 +638,6 @@ impl Eval for WhileExpr { while condition.eval(ctx, scp)?.cast::().at(condition.span())? { let body = self.body(); let value = match body.eval(ctx, scp) { - Ok(value) => value, Err(Control::Break(_)) => break, Err(Control::Continue(_)) => continue, other => other?, @@ -661,14 +664,12 @@ impl Eval for ForExpr { let body = self.body(); let value = match body.eval(ctx, scp) { - Ok(value) => value, Err(Control::Break(_)) => break, Err(Control::Continue(_)) => continue, other => other?, }; - output = ops::join(output, value) - .at(self.body().span())?; + output = ops::join(output, value).at(body.span())?; } scp.exit();