Skip to content

Commit

Permalink
AstGen: fix coercion scope type when stores are eliminated
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu authored and andrewrk committed Jun 6, 2022
1 parent cb5d2b6 commit 8fa88c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions test/behavior/basic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

0 comments on commit 8fa88c8

Please sign in to comment.