aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/while.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-17 20:45:55 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-17 20:45:55 -0700
commit84c2c47fae82e913286a2306d8947252ae3a42f7 (patch)
treea57dc1f9a211f3852496988ae1e09a222e9d6f29 /test/behavior/while.zig
parent2600978a9ddc295c347fd6ffe7c6ba20931b956e (diff)
downloadzig-84c2c47fae82e913286a2306d8947252ae3a42f7.tar.gz
zig-84c2c47fae82e913286a2306d8947252ae3a42f7.zip
Sema: implement else capture value
The ZIR instructions `switch_capture_else` and `switch_capture_ref` are removed because they are not needed. Instead, the prong index is set to max int for the special prong. Else prong with error sets is not handled yet. Adds a new behavior test because there was not a prior on to cover only the capture value of else on a switch.
Diffstat (limited to 'test/behavior/while.zig')
-rw-r--r--test/behavior/while.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/behavior/while.zig b/test/behavior/while.zig
index d86e061d17..15dd9ee54c 100644
--- a/test/behavior/while.zig
+++ b/test/behavior/while.zig
@@ -266,3 +266,20 @@ test "while optional 2 break statements and an else" {
try S.entry(true, false);
comptime try S.entry(true, false);
}
+
+test "while error 2 break statements and an else" {
+ if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn entry(opt_t: anyerror!bool, f: bool) !void {
+ var ok = false;
+ ok = while (opt_t) |t| {
+ if (f) break false;
+ if (t) break true;
+ } else |_| false;
+ try expect(ok);
+ }
+ };
+ try S.entry(true, false);
+ comptime try S.entry(true, false);
+}