zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 407d91f7a7c28192857b3a85055aebdffd207bf1 (tree)
parent 9d3363fee9314815b9afc55c20cfde92f38e2575
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 26 Jul 2023 18:06:19 -0700

add behavior test for switch nested break

closes #10196

Diffstat:
Mtest/behavior/switch.zig | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git 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")); +}