diff options
Diffstat (limited to 'test/behavior/switch_loop.zig')
| -rw-r--r-- | test/behavior/switch_loop.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/behavior/switch_loop.zig b/test/behavior/switch_loop.zig index d2e967e4c7..1d82957d39 100644 --- a/test/behavior/switch_loop.zig +++ b/test/behavior/switch_loop.zig @@ -249,3 +249,27 @@ test "switch loop on larger than pointer integer" { } try expect(entry == 3); } + +test "switch loop on non-exhaustive enum" { + 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_spirv) return error.SkipZigTest; // TODO + + const S = struct { + const E = enum(u8) { a, b, c, _ }; + + fn doTheTest() !void { + var start: E = undefined; + start = .a; + const result: u32 = s: switch (start) { + .a => continue :s .c, + else => continue :s @enumFromInt(123), + .b, _ => |x| break :s @intFromEnum(x), + }; + try expect(result == 123); + } + }; + try S.doTheTest(); + try comptime S.doTheTest(); +} |
