CR: I've a feeling we're not in Review anymore.

This commit is contained in:
Martin Haug 2022-02-28 14:22:49 +01:00
parent 8e0f5993f1
commit 9fde38a6f8
2 changed files with 6 additions and 6 deletions

View File

@ -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?,
};

View File

@ -58,9 +58,13 @@ pub type EvalResult<T> = Result<T, Control>;
/// 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<Value>, Span),
/// Stop the execution because an error occurred.
Err(TypError),
}
@ -634,7 +638,6 @@ impl Eval for WhileExpr {
while condition.eval(ctx, scp)?.cast::<bool>().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();