commit 8fa88c88c28420d89392a9984748070d35f18321 (tree)
parent cb5d2b691aadde5665cefc54542e3e0651ebc2fa
Author: Veikka Tuominen <git@vexu.eu>
Date: Sun, 5 Jun 2022 20:08:02 +0300
AstGen: fix coercion scope type when stores are eliminated
Diffstat:
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/src/AstGen.zig b/src/AstGen.zig
@@ -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;
}
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig
@@ -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,
+ });
+}