AstGen: fix coercion scope type when stores are eliminated

This commit is contained in:
Veikka Tuominen 2022-06-05 20:08:02 +03:00 committed by Andrew Kelley
parent cb5d2b691a
commit 8fa88c88c2
2 changed files with 15 additions and 0 deletions

View File

@ -9875,6 +9875,9 @@ const GenZir = struct {
errdefer as_scope.unstack();
as_scope.rl_ptr = try as_scope.addBin(.coerce_result_ptr, dest_type, result_ptr);
// `rl_ty_inst` needs to be set in case the stores to `rl_ptr` are eliminated.
as_scope.rl_ty_inst = dest_type;
return as_scope;
}

View File

@ -1062,3 +1062,15 @@ comptime {
s = S{ .a = 1 };
assert(s.a == 1);
}
test "switch inside @as gets correct type" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
var a: u32 = 0;
var b: [2]u32 = undefined;
b[0] = @as(u32, switch (a) {
1 => 1,
else => 0,
});
}