Skip to content

Commit cb257b4

Browse files
committed
allow non-exhaustive enums with no fields
1 parent d845698 commit cb257b4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/analyze.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,8 +2560,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
25602560

25612561
assert(!enum_type->data.enumeration.fields);
25622562
uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length;
2563-
if (field_count == 0 || (field_count == 1 &&
2564-
buf_eql_str(decl_node->data.container_decl.fields.at(0)->data.struct_field.name, "_"))) {
2563+
if (field_count == 0) {
25652564
add_node_error(g, decl_node, buf_sprintf("enums must have 1 or more fields"));
25662565

25672566
enum_type->data.enumeration.src_field_count = field_count;
@@ -2657,7 +2656,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
26572656
add_node_error(g, field_node, buf_sprintf("non-exhaustive enum must specify size"));
26582657
enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
26592658
}
2660-
if (log2_u64(field_count - 1) == enum_type->size_in_bits) {
2659+
if (field_count > 1 && log2_u64(field_count - 1) == enum_type->size_in_bits) {
26612660
add_node_error(g, field_node, buf_sprintf("non-exhaustive enum specifies every value"));
26622661
enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
26632662
}

0 commit comments

Comments
 (0)