diff --git a/src/AstGen.zig b/src/AstGen.zig index f702b74200..d2e2d31ff0 100644 --- 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 index c94b470b59..4666656fa3 100644 --- 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 new file mode 100644 index 0000000000..a99a9157e1 --- /dev/null +++ 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'