| ... | @@ -657,6 +657,20 @@ test "std.meta.tags" { | ... | @@ -657,6 +657,20 @@ test "std.meta.tags" { |
| 657 | pub fn FieldEnum(comptime T: type) type { | 657 | pub fn FieldEnum(comptime T: type) type { |
| 658 | const field_infos = fields(T); | 658 | const field_infos = fields(T); |
| 659 | | 659 | |
| | 660 | if (field_infos.len == 0) { |
| | 661 | // TODO simplify when stage1 is removed |
| | 662 | if (@import("builtin").zig_backend == .stage1) @compileError("stage1 doesn't allow empty enums"); |
| | 663 | return @Type(.{ |
| | 664 | .Enum = .{ |
| | 665 | .layout = .Auto, |
| | 666 | .tag_type = u0, |
| | 667 | .fields = &.{}, |
| | 668 | .decls = &.{}, |
| | 669 | .is_exhaustive = true, |
| | 670 | }, |
| | 671 | }); |
| | 672 | } |
| | 673 | |
| 660 | if (@typeInfo(T) == .Union) { | 674 | if (@typeInfo(T) == .Union) { |
| 661 | if (@typeInfo(T).Union.tag_type) |tag_type| { | 675 | if (@typeInfo(T).Union.tag_type) |tag_type| { |
| 662 | for (std.enums.values(tag_type)) |v, i| { | 676 | for (std.enums.values(tag_type)) |v, i| { |
| ... | @@ -728,6 +742,9 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { | ... | @@ -728,6 +742,9 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { |
| 728 | } | 742 | } |
| 729 | | 743 | |
| 730 | test "std.meta.FieldEnum" { | 744 | test "std.meta.FieldEnum" { |
| | 745 | if (comptime @import("builtin").zig_backend != .stage1) { |
| | 746 | try expectEqualEnum(enum {}, FieldEnum(struct {})); |
| | 747 | } |
| 731 | try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 })); | 748 | try expectEqualEnum(enum { a }, FieldEnum(struct { a: u8 })); |
| 732 | try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 })); | 749 | try expectEqualEnum(enum { a, b, c }, FieldEnum(struct { a: u8, b: void, c: f32 })); |
| 733 | try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 })); | 750 | try expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 })); |