| ... | @@ -591,6 +591,7 @@ pub const DeclGen = struct { | ... | @@ -591,6 +591,7 @@ pub const DeclGen = struct { |
| 591 | }, | 591 | }, |
| 592 | .Union => { | 592 | .Union => { |
| 593 | const union_obj = val.castTag(.@"union").?.data; | 593 | const union_obj = val.castTag(.@"union").?.data; |
| | 594 | const union_ty = ty.cast(Type.Payload.Union).?.data; |
| 594 | const target = dg.module.getTarget(); | 595 | const target = dg.module.getTarget(); |
| 595 | const layout = ty.unionGetLayout(target); | 596 | const layout = ty.unionGetLayout(target); |
| 596 | | 597 | |
| ... | @@ -607,11 +608,7 @@ pub const DeclGen = struct { | ... | @@ -607,11 +608,7 @@ pub const DeclGen = struct { |
| 607 | try writer.writeAll(".payload = {"); | 608 | try writer.writeAll(".payload = {"); |
| 608 | } | 609 | } |
| 609 | | 610 | |
| 610 | const index = switch (ty.tag()) { | 611 | const index = union_ty.tag_ty.enumTagFieldIndex(union_obj.tag).?; |
| 611 | .union_tagged => ty.castTag(.union_tagged).?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?, | | |
| 612 | .@"union" => ty.castTag(.@"union").?.data.tag_ty.enumTagFieldIndex(union_obj.tag).?, | | |
| 613 | else => unreachable, | | |
| 614 | }; | | |
| 615 | const field_ty = ty.unionFields().values()[index].ty; | 612 | const field_ty = ty.unionFields().values()[index].ty; |
| 616 | const field_name = ty.unionFields().keys()[index]; | 613 | const field_name = ty.unionFields().keys()[index]; |
| 617 | if (field_ty.hasCodeGenBits()) { | 614 | if (field_ty.hasCodeGenBits()) { |
| ... | @@ -815,11 +812,8 @@ pub const DeclGen = struct { | ... | @@ -815,11 +812,8 @@ pub const DeclGen = struct { |
| 815 | } | 812 | } |
| 816 | | 813 | |
| 817 | fn renderUnionTypedef(dg: *DeclGen, t: Type) error{ OutOfMemory, AnalysisFail }![]const u8 { | 814 | fn renderUnionTypedef(dg: *DeclGen, t: Type) error{ OutOfMemory, AnalysisFail }![]const u8 { |
| 818 | const fqn = switch (t.tag()) { | 815 | const union_ty = t.cast(Type.Payload.Union).?.data; |
| 819 | .@"union" => try t.castTag(.@"union").?.data.getFullyQualifiedName(dg.typedefs.allocator), | 816 | const fqn = try union_ty.getFullyQualifiedName(dg.typedefs.allocator); |
| 820 | .union_tagged => try t.castTag(.union_tagged).?.data.getFullyQualifiedName(dg.typedefs.allocator), | | |
| 821 | else => unreachable, | | |
| 822 | }; | | |
| 823 | defer dg.typedefs.allocator.free(fqn); | 817 | defer dg.typedefs.allocator.free(fqn); |
| 824 | | 818 | |
| 825 | const target = dg.module.getTarget(); | 819 | const target = dg.module.getTarget(); |