mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Prevent failure with empty struct in std.meta.DeclEnum
This commit is contained in:
parent
5f3d9e0b7a
commit
7d3e0f815d
@ -628,7 +628,7 @@ pub fn DeclEnum(comptime T: type) type {
|
||||
}
|
||||
return @Type(.{
|
||||
.@"enum" = .{
|
||||
.tag_type = std.math.IntFittingRange(0, fieldInfos.len - 1),
|
||||
.tag_type = std.math.IntFittingRange(0, if (fieldInfos.len == 0) 0 else fieldInfos.len - 1),
|
||||
.fields = &enumDecls,
|
||||
.decls = &decls,
|
||||
.is_exhaustive = true,
|
||||
@ -654,9 +654,12 @@ test DeclEnum {
|
||||
pub const b: void = {};
|
||||
pub const c: f32 = 0;
|
||||
};
|
||||
const D = struct {};
|
||||
|
||||
try expectEqualEnum(enum { a }, DeclEnum(A));
|
||||
try expectEqualEnum(enum { a, b, c }, DeclEnum(B));
|
||||
try expectEqualEnum(enum { a, b, c }, DeclEnum(C));
|
||||
try expectEqualEnum(enum {}, DeclEnum(D));
|
||||
}
|
||||
|
||||
pub fn Tag(comptime T: type) type {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user