aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-08-31 00:33:45 +0100
committermlugg <mlugg@mlugg.co.uk>2024-09-01 18:31:01 +0100
commitb7a55cd6c3ca0c4c97f266b72f741b980416456a (patch)
treeb164dd3a629abb7d1ca3aaa697712b8817e684cc /test/behavior
parentfd70d9db9960a98fb97def91aa34f56c15499ebf (diff)
downloadzig-b7a55cd6c3ca0c4c97f266b72f741b980416456a.tar.gz
zig-b7a55cd6c3ca0c4c97f266b72f741b980416456a.zip
AstGen: allow breaking from labeled switch
Also, don't use the special switch lowering for errors if the switch is labeled; this isn't currently supported. Related: #20627.
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/switch.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig
index 1cec0dfad4..f1ded573a0 100644
--- a/test/behavior/switch.zig
+++ b/test/behavior/switch.zig
@@ -961,3 +961,27 @@ test "block error return trace index is reset between prongs" {
};
try result;
}
+
+test "labeled switch with break" {
+ var six: u32 = undefined;
+ six = 6;
+
+ const val = s: switch (six) {
+ 0...4 => break :s false,
+ 5 => break :s false,
+ 6...7 => break :s true,
+ else => break :s false,
+ };
+
+ try expect(val);
+
+ // Make sure the switch is implicitly comptime!
+ const comptime_val = s: switch (@as(u32, 6)) {
+ 0...4 => break :s false,
+ 5 => break :s false,
+ 6...7 => break :s true,
+ else => break :s false,
+ };
+
+ comptime assert(comptime_val);
+}