authorgravatar for git@bob.frlBob Farrell <git@bob.frl> 2024-09-07 15:20:55+01:00
committergravatar for git@bob.frlBob Farrell <git@bob.frl> 2024-09-07 15:20:55+01:00
log7d3e0f815d4324c504b0d98323919d1980079ffa
treef80b75d358627e42df20cda9f15439fa76b2bd15
parent5f3d9e0b7a67b8a23b659ca7dada8641f55b8503

Prevent failure with empty struct in `std.meta.DeclEnum`


1 files changed, 4 insertions(+), 1 deletions(-)

lib/std/meta.zig+4-1
...@@ -628,7 +628,7 @@ pub fn DeclEnum(comptime T: type) type {...@@ -628,7 +628,7 @@ pub fn DeclEnum(comptime T: type) type {
628 }628 }
629 return @Type(.{629 return @Type(.{
630 .@"enum" = .{630 .@"enum" = .{
631 .tag_type = std.math.IntFittingRange(0, fieldInfos.len - 1),631 .tag_type = std.math.IntFittingRange(0, if (fieldInfos.len == 0) 0 else fieldInfos.len - 1),
632 .fields = &enumDecls,632 .fields = &enumDecls,
633 .decls = &decls,633 .decls = &decls,
634 .is_exhaustive = true,634 .is_exhaustive = true,
...@@ -654,9 +654,12 @@ test DeclEnum {...@@ -654,9 +654,12 @@ test DeclEnum {
654 pub const b: void = {};654 pub const b: void = {};
655 pub const c: f32 = 0;655 pub const c: f32 = 0;
656 };656 };
657 const D = struct {};
658
657 try expectEqualEnum(enum { a }, DeclEnum(A));659 try expectEqualEnum(enum { a }, DeclEnum(A));
658 try expectEqualEnum(enum { a, b, c }, DeclEnum(B));660 try expectEqualEnum(enum { a, b, c }, DeclEnum(B));
659 try expectEqualEnum(enum { a, b, c }, DeclEnum(C));661 try expectEqualEnum(enum { a, b, c }, DeclEnum(C));
662 try expectEqualEnum(enum {}, DeclEnum(D));
660}663}
661664
662pub fn Tag(comptime T: type) type {665pub fn Tag(comptime T: type) type {