| author | |
| committer | |
| log | 6484e279e54fc4232bae911dbe6fb76aa9e711ed |
| tree | 766b828e7d15a935a0bcadac7e1a6425107bd416 |
| parent | b0d9bb0bb844cb647942f7f1e3e7d06fc12e8df6 |
Closes #170842 files changed, 13 insertions(+), 1 deletions(-)
src/AstGen.zig+6-1| ... | @@ -1454,7 +1454,12 @@ fn arrayInitExpr( | ... | @@ -1454,7 +1454,12 @@ fn arrayInitExpr( |
| 1454 | }, | 1454 | }, |
| 1455 | .ty, .coerced_ty => |ty_inst| { | 1455 | .ty, .coerced_ty => |ty_inst| { |
| 1456 | const arr_ty = if (types.array != .none) types.array else blk: { | 1456 | 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; | ||
| 1458 | }; | 1463 | }; |
| 1459 | const result = try arrayInitExprInner(gz, scope, node, array_init.ast.elements, arr_ty, types.elem, .array_init); | 1464 | const result = try arrayInitExprInner(gz, scope, node, array_init.ast.elements, arr_ty, types.elem, .array_init); |
| 1460 | return rvalue(gz, ri, result, node); | 1465 | 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 { | ... | @@ -24,6 +24,12 @@ pub export fn entry2() void { |
| 24 | var bla: A = .{ 1, 2, 3, 4 }; | 24 | var bla: A = .{ 1, 2, 3, 4 }; |
| 25 | _ = bla; | 25 | _ = bla; |
| 26 | } | 26 | } |
| 27 | const S = struct { | ||
| 28 | list: [2]u8 = .{0}, | ||
| 29 | }; | ||
| 30 | export fn entry3() void { | ||
| 31 | _ = S{}; | ||
| 32 | } | ||
| 27 | 33 | ||
| 28 | // error | 34 | // error |
| 29 | // backend=stage2 | 35 | // backend=stage2 |
| ... | @@ -35,3 +41,4 @@ pub export fn entry2() void { | ... | @@ -35,3 +41,4 @@ pub export fn entry2() void { |
| 35 | // :16:17: error: expected 8 array elements; found 0 | 41 | // :16:17: error: expected 8 array elements; found 0 |
| 36 | // :20:19: error: expected 8 vector elements; found 4 | 42 | // :20:19: error: expected 8 vector elements; found 4 |
| 37 | // :24:19: error: expected 8 array elements; found 4 | 43 | // :24:19: error: expected 8 array elements; found 4 |
| 44 | // :28:20: error: expected 2 array elements; found 1 |