authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-08 02:31:59+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-08 06:56:52+00:00
log4504e03a18d75d0c9e4695250c807b3b4a953791
treeb517318ae077a2102c4f1bfbcf2b165f4381b5c0
parentee47643b6eb175f4414a50c19afa0c22b2d15949

Sema: fix source location for untyped array init with result type

Resolves: #17923

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

src/Sema.zig+1-1
......@@ -4400,7 +4400,7 @@ fn zirValidateArrayInitTy(
44004400 const mod = sema.mod;
44014401 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
44024402 const src = inst_data.src();
4403 const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };
4403 const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node };
44044404 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
44054405 const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {
44064406 // It's okay for the type to be unknown: this will result in an anonymous array init.
test/cases/compile_errors/array_init_not_supported_on_result_type.zig created+11
......@@ -0,0 +1,11 @@
1fn dummy(_: u32) void {}
2
3export fn foo() void {
4 dummy(.{ 1, 2 });
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// :4:12: error: type 'u32' does not support array initialization syntax