diff --git a/src/Sema.zig b/src/Sema.zig index b6cd17f438..8e34c9e4dc 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -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. diff --git a/test/cases/compile_errors/array_init_not_supported_on_result_type.zig b/test/cases/compile_errors/array_init_not_supported_on_result_type.zig new file mode 100644 index 0000000000..c56440b48a --- /dev/null +++ b/test/cases/compile_errors/array_init_not_supported_on_result_type.zig @@ -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