diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 9f8a2f21da..8b42e8e484 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2194,6 +2194,9 @@ pub fn (mut c Checker) const_decl(mut node ast.ConstDecl) { pub fn (mut c Checker) enum_decl(decl ast.EnumDecl) { c.check_valid_pascal_case(decl.name, 'enum name', decl.pos) mut seen := []i64{} + if decl.fields.len == 0 { + c.error('enum cannot be empty', decl.pos) + } for i, field in decl.fields { if !c.pref.experimental && util.contains_capital(field.name) { // TODO C2V uses hundreds of enums with capitals, remove -experimental check once it's handled diff --git a/vlib/v/checker/tests/enum_empty.out b/vlib/v/checker/tests/enum_empty.out new file mode 100644 index 0000000000..b2b432dcff --- /dev/null +++ b/vlib/v/checker/tests/enum_empty.out @@ -0,0 +1,3 @@ +vlib/v/checker/tests/enum_empty.vv:1:1: error: enum cannot be empty + 1 | enum Empty {} + | ~~~~~~~~~~ diff --git a/vlib/v/checker/tests/enum_empty.vv b/vlib/v/checker/tests/enum_empty.vv new file mode 100644 index 0000000000..7afdbc006a --- /dev/null +++ b/vlib/v/checker/tests/enum_empty.vv @@ -0,0 +1 @@ +enum Empty {}