commit ff0e2ab3983f0be241e02c1f37db795e5d02ed56 (tree)
parent 660955c0d64fdbda41e1ff7dddc40c5c4393c42c
Author: Anton Lilja <12533691+antlilja@users.noreply.github.com>
Date: Wed, 12 Jul 2023 08:35:50 +0200
Fixes wrong error location for unionInit when first parameter is not a type (#16384)
Diffstat:
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/AstGen.zig b/src/AstGen.zig
@@ -7936,7 +7936,7 @@ fn unionInit(
) InnerError!Zir.Inst.Ref {
const union_type = try typeExpr(gz, scope, params[0]);
const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[1]);
- const field_type = try gz.addPlNode(.field_type_ref, params[1], Zir.Inst.FieldTypeRef{
+ const field_type = try gz.addPlNode(.field_type_ref, node, Zir.Inst.FieldTypeRef{
.container_type = union_type,
.field_name = field_name,
});
diff --git a/src/Sema.zig b/src/Sema.zig
@@ -19368,8 +19368,8 @@ fn addConstantMaybeRef(
fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
- const ty_src = inst_data.src();
- const field_src = inst_data.src();
+ const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
+ const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known");
return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src);
diff --git a/test/cases/compile_errors/union_init_with_non_type_as_first_param.zig b/test/cases/compile_errors/union_init_with_non_type_as_first_param.zig
@@ -0,0 +1,9 @@
+export fn u() void {
+ _ = @unionInit(0, "a", 0);
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :2:20: error: expected type 'type', found 'comptime_int'