diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-17 20:45:55 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-17 20:45:55 -0700 |
| commit | 84c2c47fae82e913286a2306d8947252ae3a42f7 (patch) | |
| tree | a57dc1f9a211f3852496988ae1e09a222e9d6f29 /test/behavior/switch.zig | |
| parent | 2600978a9ddc295c347fd6ffe7c6ba20931b956e (diff) | |
| download | zig-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/switch.zig')
| -rw-r--r-- | test/behavior/switch.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index 0b43876869..07b6c4b9f1 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -359,6 +359,21 @@ fn return_a_number() anyerror!i32 { return 1; } +test "switch on integer with else capturing expr" { + const S = struct { + fn doTheTest() !void { + var x: i32 = 5; + switch (x + 10) { + 14 => @panic("fail"), + 16 => @panic("fail"), + else => |e| try expect(e == 15), + } + } + }; + try S.doTheTest(); + comptime try S.doTheTest(); +} + test "else prong of switch on error set excludes other cases" { if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO |
