diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-02-28 15:47:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-28 15:47:46 +0100 |
| commit | b63c21c91d99a1554a019dc275f955d3e6a34271 (patch) | |
| tree | ae79152aba0a7b863be3574dd16d5d12e1e311df /src/eval/func.rs | |
| parent | 4f85fc3acd840ff8802035abcdcf2191689bb628 (diff) | |
| parent | 4f09233bdae8f79ebafed43e8135f1a0285bd370 (diff) | |
Merge pull request #65 from typst/control-flow
Add break, continue, and return
Diffstat (limited to 'src/eval/func.rs')
| -rw-r--r-- | src/eval/func.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/eval/func.rs b/src/eval/func.rs index cd54a140..451dcbbb 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Formatter, Write}; use std::hash::{Hash, Hasher}; use std::sync::Arc; -use super::{Cast, Eval, Scope, Scopes, Value}; +use super::{Cast, Control, Eval, Scope, Scopes, Value}; use crate::diag::{At, TypResult}; use crate::syntax::ast::Expr; use crate::syntax::{Span, Spanned}; @@ -138,7 +138,10 @@ impl Closure { } // Evaluate the body. - let value = self.body.eval(ctx, &mut scp)?; + let value = match self.body.eval(ctx, &mut scp) { + Err(Control::Return(value, _, _)) => value, + other => other?, + }; Ok(value) } |
