From 4504e03a18d75d0c9e4695250c807b3b4a953791 Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 8 Nov 2023 02:31:59 +0000 Subject: [PATCH] Sema: fix source location for untyped array init with result type Resolves: #17923 --- src/Sema.zig | 2 +- .../array_init_not_supported_on_result_type.zig | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/cases/compile_errors/array_init_not_supported_on_result_type.zig 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