aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-15 16:41:10 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-15 16:41:10 -0700
commit2c434cddd6624cfd5c71f081b9445936d25c7703 (patch)
treeb7512d9b316275efeff0c93fb034b47ae045d6d5 /src
parentd4a0d5f959b88ffc23edc4593bc75b6168acaea9 (diff)
downloadzig-2c434cddd6624cfd5c71f081b9445936d25c7703.tar.gz
zig-2c434cddd6624cfd5c71f081b9445936d25c7703.zip
AstGen: add missing coercion for const locals
A const local which had its init expression write to the result pointer, but then gets elided to directly initialize, was missing the coercion to the type annotation.
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 646560fd5a..c3e94ef631 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -2762,11 +2762,18 @@ fn varDecl(
}
gz.instructions.items.len = dst;
+ // In case the result location did not do the coercion
+ // for us so we must do it here.
+ const coerced_init = if (opt_type_inst != .none)
+ try gz.addBin(.as, opt_type_inst, init_inst)
+ else
+ init_inst;
+
if (!gz.force_comptime) {
_ = try gz.add(.{ .tag = .dbg_var_val, .data = .{
.str_op = .{
.str = ident_name,
- .operand = init_inst,
+ .operand = coerced_init,
},
} });
}
@@ -2776,7 +2783,7 @@ fn varDecl(
.parent = scope,
.gen_zir = gz,
.name = ident_name,
- .inst = init_inst,
+ .inst = coerced_init,
.token_src = name_token,
.id_cat = .@"local constant",
};