mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: do not allow empty enums (#7848)
This commit is contained in:
parent
55d5b9e724
commit
3dae44db73
@ -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
|
||||
|
3
vlib/v/checker/tests/enum_empty.out
Normal file
3
vlib/v/checker/tests/enum_empty.out
Normal file
@ -0,0 +1,3 @@
|
||||
vlib/v/checker/tests/enum_empty.vv:1:1: error: enum cannot be empty
|
||||
1 | enum Empty {}
|
||||
| ~~~~~~~~~~
|
1
vlib/v/checker/tests/enum_empty.vv
Normal file
1
vlib/v/checker/tests/enum_empty.vv
Normal file
@ -0,0 +1 @@
|
||||
enum Empty {}
|
Loading…
x
Reference in New Issue
Block a user