aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.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 /src/AstGen.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 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 59643d5279..3fd3da6bb6 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -6070,6 +6070,13 @@ fn switchExpr(
var capture_val_scope: Scope.LocalVal = undefined;
const sub_scope = blk: {
+ const capture_index = if (is_multi_case) ci: {
+ multi_case_index += 1;
+ break :ci multi_case_index - 1;
+ } else ci: {
+ scalar_case_index += 1;
+ break :ci scalar_case_index - 1;
+ };
const payload_token = case.payload_token orelse break :blk &case_scope.base;
const ident = if (token_tags[payload_token] == .asterisk)
payload_token + 1
@@ -6103,13 +6110,6 @@ fn switchExpr(
0b10 => .switch_capture_multi,
0b11 => .switch_capture_multi_ref,
};
- const capture_index = if (is_multi_case) ci: {
- multi_case_index += 1;
- break :ci multi_case_index - 1;
- } else ci: {
- scalar_case_index += 1;
- break :ci scalar_case_index - 1;
- };
break :capture try case_scope.add(.{
.tag = capture_tag,
.data = .{ .switch_capture = .{