checker: do not allow empty enums (#7848)
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) {
|
pub fn (mut c Checker) enum_decl(decl ast.EnumDecl) {
|
||||||
c.check_valid_pascal_case(decl.name, 'enum name', decl.pos)
|
c.check_valid_pascal_case(decl.name, 'enum name', decl.pos)
|
||||||
mut seen := []i64{}
|
mut seen := []i64{}
|
||||||
|
if decl.fields.len == 0 {
|
||||||
|
c.error('enum cannot be empty', decl.pos)
|
||||||
|
}
|
||||||
for i, field in decl.fields {
|
for i, field in decl.fields {
|
||||||
if !c.pref.experimental && util.contains_capital(field.name) {
|
if !c.pref.experimental && util.contains_capital(field.name) {
|
||||||
// TODO C2V uses hundreds of enums with capitals, remove -experimental check once it's handled
|
// TODO C2V uses hundreds of enums with capitals, remove -experimental check once it's handled
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
vlib/v/checker/tests/enum_empty.vv:1:1: error: enum cannot be empty
|
||||||
|
1 | enum Empty {}
|
||||||
|
| ~~~~~~~~~~
|
|
@ -0,0 +1 @@
|
||||||
|
enum Empty {}
|
Loading…
Reference in New Issue