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

Resolves: #17923
This commit is contained in:
mlugg 2023-11-08 02:31:59 +00:00 committed by Matthew Lugg
parent ee47643b6e
commit 4504e03a18
2 changed files with 12 additions and 1 deletions

View File

@ -4400,7 +4400,7 @@ fn zirValidateArrayInitTy(
const mod = sema.mod;
const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
const src = inst_data.src();
const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };
const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node };
const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {
// It's okay for the type to be unknown: this will result in an anonymous array init.

View File

@ -0,0 +1,11 @@
fn dummy(_: u32) void {}
export fn foo() void {
dummy(.{ 1, 2 });
}
// error
// backend=stage2
// target=native
//
// :4:12: error: type 'u32' does not support array initialization syntax