aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-06-26 20:41:42 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-06-26 16:20:33 -0700
commit88284c124a0d930541f02ae9727118c0724f93f9 (patch)
treeb55a7334f61f7c8a9516ee66e44aa4504d708d3a /src
parentbbda053f9e309128ee4b2eb1a5b886aeb30fcabf (diff)
downloadzig-88284c124a0d930541f02ae9727118c0724f93f9.tar.gz
zig-88284c124a0d930541f02ae9727118c0724f93f9.zip
AstGen: fix result locations for elements of typed array init
Resolves: #16226
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 27e8433cb6..ff7feef883 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -1478,9 +1478,26 @@ fn arrayInitExpr(
switch (ri.rl) {
.discard => {
- // TODO elements should still be coerced if type is provided
- for (array_init.ast.elements) |elem_init| {
- _ = try expr(gz, scope, .{ .rl = .discard }, elem_init);
+ if (types.elem != .none) {
+ const elem_ri: ResultInfo = .{ .rl = .{ .ty = types.elem } };
+ for (array_init.ast.elements) |elem_init| {
+ _ = try expr(gz, scope, elem_ri, elem_init);
+ }
+ } else if (types.array != .none) {
+ for (array_init.ast.elements, 0..) |elem_init, i| {
+ const elem_ty = try gz.add(.{
+ .tag = .elem_type_index,
+ .data = .{ .bin = .{
+ .lhs = types.array,
+ .rhs = @enumFromInt(i),
+ } },
+ });
+ _ = try expr(gz, scope, .{ .rl = .{ .ty = elem_ty } }, elem_init);
+ }
+ } else {
+ for (array_init.ast.elements) |elem_init| {
+ _ = try expr(gz, scope, .{ .rl = .discard }, elem_init);
+ }
}
return Zir.Inst.Ref.void_value;
},
@@ -1569,7 +1586,7 @@ fn arrayInitExprInner(
for (elements, 0..) |elem_init, i| {
const ri = if (elem_ty != .none)
ResultInfo{ .rl = .{ .coerced_ty = elem_ty } }
- else if (array_ty_inst != .none and nodeMayNeedMemoryLocation(astgen.tree, elem_init, true)) ri: {
+ else if (array_ty_inst != .none) ri: {
const ty_expr = try gz.add(.{
.tag = .elem_type_index,
.data = .{ .bin = .{