checker: do not allow empty enums (#7848)

pull/7877/head
zakuro 2021-01-05 09:46:32 +09:00 committed by GitHub
parent 55d5b9e724
commit 3dae44db73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
vlib/v/checker/tests/enum_empty.vv:1:1: error: enum cannot be empty
1 | enum Empty {}
| ~~~~~~~~~~

View File

@ -0,0 +1 @@
enum Empty {}