Commit 4504e03a18

mlugg <mlugg@mlugg.co.uk>
2023-11-08 03:31:59
Sema: fix source location for untyped array init with result type
Resolves: #17923
1 parent ee47643
Changed files (2)
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.
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