| ... | ... | @@ -704,9 +704,13 @@ pub const DeclGen = struct { |
| 704 | 704 | |
| 705 | 705 | try writer.writeByte('{'); |
| 706 | 706 | if (ty.unionTagTypeSafety()) |tag_ty| { |
| 707 | | try writer.writeAll(" .tag = "); |
| 708 | | try dg.renderValue(writer, tag_ty, val, .Initializer); |
| 709 | | try writer.writeAll(", .payload = {"); |
| 707 | const layout = ty.unionGetLayout(target); |
| 708 | if (layout.tag_size != 0) { |
| 709 | try writer.writeAll(" .tag = "); |
| 710 | try dg.renderValue(writer, tag_ty, val, .Initializer); |
| 711 | try writer.writeByte(','); |
| 712 | } |
| 713 | try writer.writeAll(" .payload = {"); |
| 710 | 714 | } |
| 711 | 715 | for (ty.unionFields().values()) |field| { |
| 712 | 716 | if (!field.ty.hasRuntimeBits()) continue; |
| ... | ... | @@ -1115,7 +1119,6 @@ pub const DeclGen = struct { |
| 1115 | 1119 | }, |
| 1116 | 1120 | .Union => { |
| 1117 | 1121 | const union_obj = val.castTag(.@"union").?.data; |
| 1118 | | const layout = ty.unionGetLayout(target); |
| 1119 | 1122 | |
| 1120 | 1123 | if (location != .Initializer) { |
| 1121 | 1124 | try writer.writeByte('('); |
| ... | ... | @@ -1125,6 +1128,7 @@ pub const DeclGen = struct { |
| 1125 | 1128 | |
| 1126 | 1129 | try writer.writeByte('{'); |
| 1127 | 1130 | if (ty.unionTagTypeSafety()) |tag_ty| { |
| 1131 | const layout = ty.unionGetLayout(target); |
| 1128 | 1132 | if (layout.tag_size != 0) { |
| 1129 | 1133 | try writer.writeAll(".tag = "); |
| 1130 | 1134 | try dg.renderValue(writer, tag_ty, union_obj.tag, .Initializer); |
| ... | ... | @@ -5305,7 +5309,6 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5305 | 5309 | const extra = f.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 5306 | 5310 | const union_ty = f.air.typeOfIndex(inst); |
| 5307 | 5311 | const target = f.object.dg.module.getTarget(); |
| 5308 | | const layout = union_ty.unionGetLayout(target); |
| 5309 | 5312 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 5310 | 5313 | const field_name = union_obj.fields.keys()[extra.field_index]; |
| 5311 | 5314 | const payload = try f.resolveInst(extra.init); |
| ... | ... | @@ -5314,6 +5317,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5314 | 5317 | const local = try f.allocLocal(union_ty, .Const); |
| 5315 | 5318 | try writer.writeAll(" = {"); |
| 5316 | 5319 | if (union_ty.unionTagTypeSafety()) |tag_ty| { |
| 5320 | const layout = union_ty.unionGetLayout(target); |
| 5317 | 5321 | if (layout.tag_size != 0) { |
| 5318 | 5322 | const field_index = tag_ty.enumFieldIndex(field_name).?; |
| 5319 | 5323 | |