From 877df549aae877cf53de2fe250a552358fa5aad9 Mon Sep 17 00:00:00 2001 From: bluebear94 Date: Mon, 21 Aug 2023 10:21:37 -0400 Subject: Check for control flow event before let binding (#1912) Fixes #1906 (trying to destructure the result of `continue`). --- crates/typst/src/eval/mod.rs | 3 +++ tests/ref/compiler/break-continue.png | Bin 7854 -> 9732 bytes tests/typ/compiler/break-continue.typ | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/crates/typst/src/eval/mod.rs b/crates/typst/src/eval/mod.rs index 88302c4a..f3da4263 100644 --- a/crates/typst/src/eval/mod.rs +++ b/crates/typst/src/eval/mod.rs @@ -1470,6 +1470,9 @@ impl Eval for ast::LetBinding<'_> { Some(expr) => expr.eval(vm)?, None => Value::None, }; + if vm.flow.is_some() { + return Ok(Value::None); + } match self.kind() { ast::LetBindingKind::Normal(pattern) => define_pattern(vm, pattern, value), diff --git a/tests/ref/compiler/break-continue.png b/tests/ref/compiler/break-continue.png index 66197443..9751d395 100644 Binary files a/tests/ref/compiler/break-continue.png and b/tests/ref/compiler/break-continue.png differ diff --git a/tests/typ/compiler/break-continue.typ b/tests/typ/compiler/break-continue.typ index 6f505f80..4c4738bb 100644 --- a/tests/typ/compiler/break-continue.typ +++ b/tests/typ/compiler/break-continue.typ @@ -145,3 +145,18 @@ for _ in range(3) [B] ) } + +--- +// Ref: true +// Test continue while destructuring. +// Should output "one = I \ two = II \ one = I". +#for num in (1, 2, 3, 1) { + let (word, roman) = if num == 1 { + ("one", "I") + } else if num == 2 { + ("two", "II") + } else { + continue + } + [#word = #roman \ ] +} -- cgit v1.2.3