diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-12-29 12:58:47 +0100 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-12-30 09:42:20 +0100 |
| commit | 88634f0481fb1bd78f8d018b76cab6590691c8a9 (patch) | |
| tree | 68f4e1cc2f26f176de68c880e83b8f2484165928 /test | |
| parent | 3634d44d08c73326c7783cf2a3095acb50eb2e1c (diff) | |
| download | zig-88634f0481fb1bd78f8d018b76cab6590691c8a9.tar.gz zig-88634f0481fb1bd78f8d018b76cab6590691c8a9.zip | |
stage1: Allow variable capture for multi-prong switch arms
Handle the multi-prong case as we do with range cases.
Closes #7188
Diffstat (limited to 'test')
| -rw-r--r-- | test/stage1/behavior/switch.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig index 28979b8ae8..20ca0d3146 100644 --- a/test/stage1/behavior/switch.zig +++ b/test/stage1/behavior/switch.zig @@ -436,6 +436,26 @@ test "switch with disjoint range" { } } +test "switch variable for range and multiple prongs" { + const S = struct { + fn doTheTest() void { + var u: u8 = 16; + doTheSwitch(u); + comptime doTheSwitch(u); + var v: u8 = 42; + doTheSwitch(v); + comptime doTheSwitch(v); + } + fn doTheSwitch(q: u8) void { + switch (q) { + 0...40 => |x| expect(x == 16), + 41, 42, 43 => |x| expect(x == 42), + else => expect(false), + } + } + }; +} + var state: u32 = 0; fn poll() void { switch (state) { |
