authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-26 18:06:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-26 19:02:02-07:00
log407d91f7a7c28192857b3a85055aebdffd207bf1
treefb4ab69d66bddb7ac897d686916da528c41eec95
parent9d3363fee9314815b9afc55c20cfde92f38e2575

add behavior test for switch nested break

closes #10196

1 files changed, 19 insertions(+), 0 deletions(-)

test/behavior/switch.zig+19
......@@ -797,3 +797,22 @@ test "inline switch range that includes the maximum value of the switched type"
797797 }
798798 }
799799}
800
801test "nested break ignores switch conditions and breaks instead" {
802 const S = struct {
803 fn register_to_address(ident: []const u8) !u8 {
804 const reg: u8 = if (std.mem.eql(u8, ident, "zero")) 0x00 else blk: {
805 break :blk switch (ident[0]) {
806 0x61 => (try std.fmt.parseInt(u8, ident[1..], 0)) + 1,
807 0x66 => (try std.fmt.parseInt(u8, ident[1..], 0)) + 1,
808 else => {
809 break :blk 0xFF;
810 },
811 };
812 };
813 return reg;
814 }
815 };
816 // Originally reported at https://github.com/ziglang/zig/issues/10196
817 try expect(0x01 == try S.register_to_address("a0"));
818}