mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
Fixes wrong error location for unionInit when first parameter is not a type (#16384)
This commit is contained in:
parent
660955c0d6
commit
ff0e2ab398
@ -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,
|
||||
});
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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'
|
||||
Loading…
x
Reference in New Issue
Block a user