mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
allow non-exhaustive enums with no fields
This commit is contained in:
parent
d84569895c
commit
cb257b4e11
@ -2560,8 +2560,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
|
||||
|
||||
assert(!enum_type->data.enumeration.fields);
|
||||
uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length;
|
||||
if (field_count == 0 || (field_count == 1 &&
|
||||
buf_eql_str(decl_node->data.container_decl.fields.at(0)->data.struct_field.name, "_"))) {
|
||||
if (field_count == 0) {
|
||||
add_node_error(g, decl_node, buf_sprintf("enums must have 1 or more fields"));
|
||||
|
||||
enum_type->data.enumeration.src_field_count = field_count;
|
||||
@ -2657,7 +2656,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
|
||||
add_node_error(g, field_node, buf_sprintf("non-exhaustive enum must specify size"));
|
||||
enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
|
||||
}
|
||||
if (log2_u64(field_count - 1) == enum_type->size_in_bits) {
|
||||
if (field_count > 1 && log2_u64(field_count - 1) == enum_type->size_in_bits) {
|
||||
add_node_error(g, field_node, buf_sprintf("non-exhaustive enum specifies every value"));
|
||||
enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user