parser: check enum name and field name errors
parent
85763d0539
commit
5f435fa1cc
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/enum_field_name_err.v:2:5: error: field name `Green` must be all lowercase
|
||||||
|
1 | enum Color {
|
||||||
|
2 | Green
|
||||||
|
| ~~~~~
|
||||||
|
3 | yellow
|
||||||
|
4 | }
|
|
@ -0,0 +1,7 @@
|
||||||
|
enum Color {
|
||||||
|
Green
|
||||||
|
yellow
|
||||||
|
}
|
||||||
|
fn main(){
|
||||||
|
println('hello')
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
vlib/v/checker/tests/enum_name_err.v:1:6: error: enum name `color` must begin with a capital letter
|
||||||
|
1 | enum color {
|
||||||
|
| ~~~~~
|
||||||
|
2 | green
|
||||||
|
3 | yellow
|
|
@ -0,0 +1,7 @@
|
||||||
|
enum color {
|
||||||
|
green
|
||||||
|
yellow
|
||||||
|
}
|
||||||
|
fn main(){
|
||||||
|
println('hello')
|
||||||
|
}
|
|
@ -1146,7 +1146,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
||||||
end_pos := p.tok.position()
|
end_pos := p.tok.position()
|
||||||
enum_name := p.check_name()
|
enum_name := p.check_name()
|
||||||
if enum_name.len > 0 && !enum_name[0].is_capital() {
|
if enum_name.len > 0 && !enum_name[0].is_capital() {
|
||||||
verror('enum name `$enum_name` must begin with a capital letter')
|
p.error_with_pos('enum name `$enum_name` must begin with a capital letter', end_pos)
|
||||||
}
|
}
|
||||||
name := p.prepend_mod(enum_name)
|
name := p.prepend_mod(enum_name)
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
|
@ -1156,6 +1156,9 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
|
||||||
for p.tok.kind != .eof && p.tok.kind != .rcbr {
|
for p.tok.kind != .eof && p.tok.kind != .rcbr {
|
||||||
pos := p.tok.position()
|
pos := p.tok.position()
|
||||||
val := p.check_name()
|
val := p.check_name()
|
||||||
|
if !val.is_lower() {
|
||||||
|
p.error_with_pos('field name `$val` must be all lowercase', pos)
|
||||||
|
}
|
||||||
vals << val
|
vals << val
|
||||||
mut expr := ast.Expr{}
|
mut expr := ast.Expr{}
|
||||||
mut has_expr := false
|
mut has_expr := false
|
||||||
|
|
Loading…
Reference in New Issue