diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-07-26 18:06:19 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-07-26 19:02:02 -0700 |
| commit | 407d91f7a7c28192857b3a85055aebdffd207bf1 (patch) | |
| tree | fb4ab69d66bddb7ac897d686916da528c41eec95 /test/behavior | |
| parent | 9d3363fee9314815b9afc55c20cfde92f38e2575 (diff) | |
| download | zig-407d91f7a7c28192857b3a85055aebdffd207bf1.tar.gz zig-407d91f7a7c28192857b3a85055aebdffd207bf1.zip | |
add behavior test for switch nested break
closes #10196
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/switch.zig | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index 0ae7c510ef..7d90247a30 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -797,3 +797,22 @@ test "inline switch range that includes the maximum value of the switched type" } } } + +test "nested break ignores switch conditions and breaks instead" { + const S = struct { + fn register_to_address(ident: []const u8) !u8 { + const reg: u8 = if (std.mem.eql(u8, ident, "zero")) 0x00 else blk: { + break :blk switch (ident[0]) { + 0x61 => (try std.fmt.parseInt(u8, ident[1..], 0)) + 1, + 0x66 => (try std.fmt.parseInt(u8, ident[1..], 0)) + 1, + else => { + break :blk 0xFF; + }, + }; + }; + return reg; + } + }; + // Originally reported at https://github.com/ziglang/zig/issues/10196 + try expect(0x01 == try S.register_to_address("a0")); +} |
