diff options
| author | David Rubin <daviru007@icloud.com> | 2024-12-27 04:19:50 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-12-29 13:36:52 -0500 |
| commit | b99dbb6fb50e7b10f05287470df577b2726754fa (patch) | |
| tree | 08b51df86ab4e0514a36cf5e601654960e6c645c /test/behavior/switch_loop.zig | |
| parent | 01081cc8e8b79104f7992d60dbd1bc8682e8fedf (diff) | |
| download | zig-b99dbb6fb50e7b10f05287470df577b2726754fa.tar.gz zig-b99dbb6fb50e7b10f05287470df577b2726754fa.zip | |
Value: implement `orderAgainstZeroInner` for errors
Diffstat (limited to 'test/behavior/switch_loop.zig')
| -rw-r--r-- | test/behavior/switch_loop.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/behavior/switch_loop.zig b/test/behavior/switch_loop.zig index d35a4e1636..6bc268e390 100644 --- a/test/behavior/switch_loop.zig +++ b/test/behavior/switch_loop.zig @@ -74,6 +74,31 @@ test "switch loop on enum" { try comptime S.doTheTest(); } +test "switch loop with error set" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO + + const S = struct { + const E = error{ Foo, Bar, Baz }; + + fn doTheTest() !void { + var start: E = undefined; + start = error.Foo; + const result: u32 = s: switch (start) { + error.Foo => continue :s error.Bar, + error.Bar => continue :s error.Baz, + error.Baz => 123, + }; + try expect(result == 123); + } + }; + try S.doTheTest(); + try comptime S.doTheTest(); +} + test "switch loop on tagged union" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
