mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 16:24:51 +00:00
AstGen: fix coercion scope type when stores are eliminated
This commit is contained in:
parent
cb5d2b691a
commit
8fa88c88c2
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user