parser: dont allow single letter enums (#6526)
parent
f55f2fb9d1
commit
a57e01fee7
|
@ -0,0 +1,5 @@
|
|||
vlib/v/checker/tests/enum_single_letter.vv:1:6: error: single letter capital names are reserved for generic template types.
|
||||
1 | enum E {
|
||||
| ^
|
||||
2 | v w
|
||||
3 | }
|
|
@ -0,0 +1,4 @@
|
|||
enum E {
|
||||
v w
|
||||
}
|
||||
println(E.v)
|
|
@ -206,7 +206,7 @@ pub fn (mut p Parser) parse_any_type(language table.Language, is_ptr, check_dot
|
|||
}
|
||||
} else if p.expr_mod != '' {
|
||||
name = p.expr_mod + '.' + name
|
||||
} else if p.mod != 'builtin' && name !in p.table.type_idxs && name.len > 1 {
|
||||
} else if p.mod != 'builtin' && name.len > 1 && name !in p.table.type_idxs {
|
||||
// `Foo` in module `mod` means `mod.Foo`
|
||||
name = p.mod + '.' + name
|
||||
}
|
||||
|
|
|
@ -1723,6 +1723,10 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
|||
p.check(.key_enum)
|
||||
end_pos := p.tok.position()
|
||||
enum_name := p.check_name()
|
||||
if enum_name.len == 1 {
|
||||
p.error_with_pos('single letter capital names are reserved for generic template types.',
|
||||
end_pos)
|
||||
}
|
||||
name := p.prepend_mod(enum_name)
|
||||
p.check(.lcbr)
|
||||
enum_decl_comments := p.eat_comments()
|
||||
|
|
Loading…
Reference in New Issue