authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-05 20:08:02+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-06 13:11:50-07:00
log8fa88c88c28420d89392a9984748070d35f18321
tree37957568ca213e1af27b88972efa21bd91bbfbf4
parentcb5d2b691aadde5665cefc54542e3e0651ebc2fa

AstGen: fix coercion scope type when stores are eliminated


2 files changed, 15 insertions(+), 0 deletions(-)

src/AstGen.zig+3
......@@ -9875,6 +9875,9 @@ const GenZir = struct {
98759875 errdefer as_scope.unstack();
98769876 as_scope.rl_ptr = try as_scope.addBin(.coerce_result_ptr, dest_type, result_ptr);
98779877
9878 // `rl_ty_inst` needs to be set in case the stores to `rl_ptr` are eliminated.
9879 as_scope.rl_ty_inst = dest_type;
9880
98789881 return as_scope;
98799882 }
98809883
test/behavior/basic.zig+12
......@@ -1062,3 +1062,15 @@ comptime {
10621062 s = S{ .a = 1 };
10631063 assert(s.a == 1);
10641064}
1065
1066test "switch inside @as gets correct type" {
1067 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1068 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1069
1070 var a: u32 = 0;
1071 var b: [2]u32 = undefined;
1072 b[0] = @as(u32, switch (a) {
1073 1 => 1,
1074 else => 0,
1075 });
1076}