authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-09-07 12:58:36+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-09-07 16:56:07+03:00
log6484e279e54fc4232bae911dbe6fb76aa9e711ed
tree766b828e7d15a935a0bcadac7e1a6425107bd416
parentb0d9bb0bb844cb647942f7f1e3e7d06fc12e8df6

AstGen: fix missing array type validation

Closes #17084

2 files changed, 13 insertions(+), 1 deletions(-)

src/AstGen.zig+6-1
......@@ -1454,7 +1454,12 @@ fn arrayInitExpr(
14541454 },
14551455 .ty, .coerced_ty => |ty_inst| {
14561456 const arr_ty = if (types.array != .none) types.array else blk: {
1457 break :blk try gz.addUnNode(.opt_eu_base_ty, ty_inst, node);
1457 const arr_ty = try gz.addUnNode(.opt_eu_base_ty, ty_inst, node);
1458 _ = try gz.addPlNode(.validate_array_init_ty, node, Zir.Inst.ArrayInit{
1459 .ty = arr_ty,
1460 .init_count = @intCast(array_init.ast.elements.len),
1461 });
1462 break :blk arr_ty;
14581463 };
14591464 const result = try arrayInitExprInner(gz, scope, node, array_init.ast.elements, arr_ty, types.elem, .array_init);
14601465 return rvalue(gz, ri, result, node);
test/cases/compile_errors/array_init_invalid_elem_count.zig+7
......@@ -24,6 +24,12 @@ pub export fn entry2() void {
2424 var bla: A = .{ 1, 2, 3, 4 };
2525 _ = bla;
2626}
27const S = struct {
28 list: [2]u8 = .{0},
29};
30export fn entry3() void {
31 _ = S{};
32}
2733
2834// error
2935// backend=stage2
......@@ -35,3 +41,4 @@ pub export fn entry2() void {
3541// :16:17: error: expected 8 array elements; found 0
3642// :20:19: error: expected 8 vector elements; found 4
3743// :24:19: error: expected 8 array elements; found 4
44// :28:20: error: expected 2 array elements; found 1