aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-06 17:31:43 -0800
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2022-03-07 07:30:30 -0800
commitc9fac41368c872d424681ea3cf93a9d97157143e (patch)
tree887f6058136580aad6110a329d82038ba71ad663 /src/AstGen.zig
parentc7e4c711fc5795e66f974316611922a0b962eb99 (diff)
downloadzig-c9fac41368c872d424681ea3cf93a9d97157143e.tar.gz
zig-c9fac41368c872d424681ea3cf93a9d97157143e.zip
stage2: resolve array type for typed array init expressions
Array types with sentinels were not being typed correctly in the translation from ZIR to Sema (comptime). This modifies the `array_init` ZIR to also retain the type of the init expression (note: untyped array initialization is done via the `array_init_anon` ZIR and so is unchanged in this commit).
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index cb710af900..8197589523 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -1319,25 +1319,25 @@ fn arrayInitExpr(
},
.ref => {
if (types.array != .none) {
- return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init_ref);
+ return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, types.array, .array_init_ref);
} else {
return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon_ref);
}
},
.none => {
if (types.array != .none) {
- return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init);
+ return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, types.array, .array_init);
} else {
return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon);
}
},
.ty, .coerced_ty => |ty_inst| {
if (types.array != .none) {
- const result = try arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init);
+ const result = try arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, types.array, .array_init);
return rvalue(gz, rl, result, node);
} else {
const elem_type = try gz.addUnNode(.elem_type, ty_inst, node);
- return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, elem_type, .array_init);
+ return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, elem_type, types.array, .array_init);
}
},
.ptr => |ptr_inst| {
@@ -1387,14 +1387,18 @@ fn arrayInitExprRlTy(
node: Ast.Node.Index,
elements: []const Ast.Node.Index,
elem_ty_inst: Zir.Inst.Ref,
+ array_ty: Zir.Inst.Ref,
tag: Zir.Inst.Tag,
) InnerError!Zir.Inst.Ref {
const astgen = gz.astgen;
const payload_index = try addExtra(astgen, Zir.Inst.MultiOp{
- .operands_len = @intCast(u32, elements.len),
+ .operands_len = @intCast(u32, elements.len + 1),
});
- var extra_index = try reserveExtra(astgen, elements.len);
+ var extra_index = try reserveExtra(astgen, elements.len + 1);
+
+ astgen.extra.items[extra_index] = @enumToInt(array_ty);
+ extra_index += 1;
const elem_rl: ResultLoc = .{ .ty = elem_ty_inst };
for (elements) |elem_init| {