authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-06 02:52:20+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-10-06 02:52:20+02:00
logac247c9943385dce3d90647e26387914f65979b9
tree3d0db53b269a4fcf06b904babcc258192af03aa7
parent406e56ab698358ee9be6746b2328689bf203022e
parent7d3e0f815d4324c504b0d98323919d1980079ffa
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21331 from bobf/std-meta-DeclEnum-empty-struct

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

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

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