Commit 407d91f7a7

Andrew Kelley <andrew@ziglang.org>
2023-07-27 03:06:19
add behavior test for switch nested break
closes #10196
1 parent 9d3363f
Changed files (1)
test
behavior
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"));
+}