authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2023-07-12 08:35:50+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-11 23:35:50-07:00
logff0e2ab3983f0be241e02c1f37db795e5d02ed56
treebde59ee7be0d43d60bc61e3651e7caf503b41ab2
parent660955c0d64fdbda41e1ff7dddc40c5c4393c42c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Fixes wrong error location for unionInit when first parameter is not a type (#16384)


3 files changed, 12 insertions(+), 3 deletions(-)

src/AstGen.zig+1-1
......@@ -7936,7 +7936,7 @@ fn unionInit(
79367936) InnerError!Zir.Inst.Ref {
79377937 const union_type = try typeExpr(gz, scope, params[0]);
79387938 const field_name = try comptimeExpr(gz, scope, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[1]);
7939 const field_type = try gz.addPlNode(.field_type_ref, params[1], Zir.Inst.FieldTypeRef{
7939 const field_type = try gz.addPlNode(.field_type_ref, node, Zir.Inst.FieldTypeRef{
79407940 .container_type = union_type,
79417941 .field_name = field_name,
79427942 });
src/Sema.zig+2-2
......@@ -19368,8 +19368,8 @@ fn addConstantMaybeRef(
1936819368fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1936919369 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1937019370 const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
19371 const ty_src = inst_data.src();
19372 const field_src = inst_data.src();
19371 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
19372 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1937319373 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
1937419374 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known");
1937519375 return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src);
test/cases/compile_errors/union_init_with_non_type_as_first_param.zig created+9
......@@ -0,0 +1,9 @@
1export fn u() void {
2 _ = @unionInit(0, "a", 0);
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:20: error: expected type 'type', found 'comptime_int'