| author | |
| committer | |
| log | ff0e2ab3983f0be241e02c1f37db795e5d02ed56 |
| tree | bde59ee7be0d43d60bc61e3651e7caf503b41ab2 |
| parent | 660955c0d64fdbda41e1ff7dddc40c5c4393c42c |
| signature |
3 files changed, 12 insertions(+), 3 deletions(-)
src/AstGen.zig+1-1| ... | ... | @@ -7936,7 +7936,7 @@ fn unionInit( |
| 7936 | 7936 | ) InnerError!Zir.Inst.Ref { |
| 7937 | 7937 | const union_type = try typeExpr(gz, scope, params[0]); |
| 7938 | 7938 | 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{ | |
| 7940 | 7940 | .container_type = union_type, |
| 7941 | 7941 | .field_name = field_name, |
| 7942 | 7942 | }); |
src/Sema.zig+2-2| ... | ... | @@ -19368,8 +19368,8 @@ fn addConstantMaybeRef( |
| 19368 | 19368 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19369 | 19369 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 19370 | 19370 | 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 }; | |
| 19373 | 19373 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 19374 | 19374 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known"); |
| 19375 | 19375 | 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 @@ |
| 1 | export 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' |