Skip to content

Commit 407d91f

Browse files
committed
add behavior test for switch nested break
closes #10196
1 parent 9d3363f commit 407d91f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/behavior/switch.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,22 @@ test "inline switch range that includes the maximum value of the switched type"
797797
}
798798
}
799799
}
800+
801+
test "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+
}

0 commit comments

Comments
 (0)