aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/switch.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-10-26 17:33:35 +0200
committerAndrew Kelley <andrew@ziglang.org>2021-10-26 14:51:33 -0400
commit25012ab3d12ac7bcd4e53a90367afc8e97d91c36 (patch)
tree23a034934cd1d6ec3676b0d0aca9c092ae7e1b6d /test/behavior/switch.zig
parent17e46a3b97479b13a46a933206fca94d959fafe8 (diff)
downloadzig-25012ab3d12ac7bcd4e53a90367afc8e97d91c36.tar.gz
zig-25012ab3d12ac7bcd4e53a90367afc8e97d91c36.zip
astgen: generate correct switch prong indices
Switch prong values are fetched by index in semantic analysis by prong offset, but these were computed as capture offset. This means that a switch where the first prong does not capture and the second does, the switch_capture zir instruction would be assigned switch_prong 0 instead of 1.
Diffstat (limited to 'test/behavior/switch.zig')
-rw-r--r--test/behavior/switch.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig
index 6df3656760..3ec49a060a 100644
--- a/test/behavior/switch.zig
+++ b/test/behavior/switch.zig
@@ -299,3 +299,17 @@ fn testSwitchHandleAllCasesRange(x: u8) u8 {
204...255 => 3,
};
}
+
+test "switch on union with some prongs capturing" {
+ const X = union(enum) {
+ a,
+ b: i32,
+ };
+
+ var x: X = X{ .b = 10 };
+ var y: i32 = switch (x) {
+ .a => unreachable,
+ .b => |b| b + 1,
+ };
+ try expect(y == 11);
+}