| ... | @@ -15885,6 +15885,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -15885,6 +15885,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 15885 | .Struct => return sema.structInitEmpty(block, obj_ty, src, src), | 15885 | .Struct => return sema.structInitEmpty(block, obj_ty, src, src), |
| 15886 | .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty), | 15886 | .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty), |
| 15887 | .Void => return sema.addConstant(obj_ty, Value.void), | 15887 | .Void => return sema.addConstant(obj_ty, Value.void), |
| | 15888 | .Union => return sema.fail(block, src, "union initializer must initialize one field", .{}), |
| 15888 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), | 15889 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), |
| 15889 | } | 15890 | } |
| 15890 | } | 15891 | } |
| ... | @@ -25854,14 +25855,19 @@ fn coerceAnonStructToUnion( | ... | @@ -25854,14 +25855,19 @@ fn coerceAnonStructToUnion( |
| 25854 | inst_src: LazySrcLoc, | 25855 | inst_src: LazySrcLoc, |
| 25855 | ) !Air.Inst.Ref { | 25856 | ) !Air.Inst.Ref { |
| 25856 | const inst_ty = sema.typeOf(inst); | 25857 | const inst_ty = sema.typeOf(inst); |
| 25857 | const anon_struct = inst_ty.castTag(.anon_struct).?.data; | 25858 | const field_count = inst_ty.structFieldCount(); |
| 25858 | if (anon_struct.types.len != 1) { | 25859 | if (field_count != 1) { |
| 25859 | const msg = msg: { | 25860 | const msg = msg: { |
| 25860 | const msg = try sema.errMsg( | 25861 | const msg = if (field_count > 1) try sema.errMsg( |
| 25861 | block, | 25862 | block, |
| 25862 | inst_src, | 25863 | inst_src, |
| 25863 | "cannot initialize multiple union fields at once, unions can only have one active field", | 25864 | "cannot initialize multiple union fields at once, unions can only have one active field", |
| 25864 | .{}, | 25865 | .{}, |
| | 25866 | ) else try sema.errMsg( |
| | 25867 | block, |
| | 25868 | inst_src, |
| | 25869 | "union initializer must initialize one field", |
| | 25870 | .{}, |
| 25865 | ); | 25871 | ); |
| 25866 | errdefer msg.destroy(sema.gpa); | 25872 | errdefer msg.destroy(sema.gpa); |
| 25867 | | 25873 | |
| ... | @@ -25874,6 +25880,7 @@ fn coerceAnonStructToUnion( | ... | @@ -25874,6 +25880,7 @@ fn coerceAnonStructToUnion( |
| 25874 | return sema.failWithOwnedErrorMsg(msg); | 25880 | return sema.failWithOwnedErrorMsg(msg); |
| 25875 | } | 25881 | } |
| 25876 | | 25882 | |
| | 25883 | const anon_struct = inst_ty.castTag(.anon_struct).?.data; |
| 25877 | const field_name = anon_struct.names[0]; | 25884 | const field_name = anon_struct.names[0]; |
| 25878 | const init = try sema.structFieldVal(block, inst_src, inst, field_name, inst_src, inst_ty); | 25885 | const init = try sema.structFieldVal(block, inst_src, inst, field_name, inst_src, inst_ty); |
| 25879 | return sema.unionInit(block, init, inst_src, union_ty, union_ty_src, field_name, inst_src); | 25886 | return sema.unionInit(block, init, inst_src, union_ty, union_ty_src, field_name, inst_src); |