parser: make sure interface field names use uppercase letters (#14228)
parent
85cb0a8c85
commit
f4586b1577
|
@ -0,0 +1,20 @@
|
||||||
|
vlib/v/checker/tests/interface_field_name_err.vv:2:2: error: field name `Age` cannot contain uppercase letters, use snake_case instead
|
||||||
|
1 | interface Animal {
|
||||||
|
2 | Age int
|
||||||
|
| ~~~
|
||||||
|
3 | Foo &int
|
||||||
|
4 | Bar []string
|
||||||
|
vlib/v/checker/tests/interface_field_name_err.vv:3:2: error: field name `Foo` cannot contain uppercase letters, use snake_case instead
|
||||||
|
1 | interface Animal {
|
||||||
|
2 | Age int
|
||||||
|
3 | Foo &int
|
||||||
|
| ~~~
|
||||||
|
4 | Bar []string
|
||||||
|
5 | }
|
||||||
|
vlib/v/checker/tests/interface_field_name_err.vv:4:2: error: field name `Bar` cannot contain uppercase letters, use snake_case instead
|
||||||
|
2 | Age int
|
||||||
|
3 | Foo &int
|
||||||
|
4 | Bar []string
|
||||||
|
| ~~~
|
||||||
|
5 | }
|
||||||
|
6 |
|
|
@ -0,0 +1,8 @@
|
||||||
|
interface Animal {
|
||||||
|
Age int
|
||||||
|
Foo &int
|
||||||
|
Bar []string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
|
@ -517,7 +517,8 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
||||||
mut ifaces := []ast.InterfaceEmbedding{}
|
mut ifaces := []ast.InterfaceEmbedding{}
|
||||||
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
||||||
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
|
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
|
||||||
&& p.peek_tok.kind != .lpar {
|
&& (p.peek_tok.line_nr != p.tok.line_nr
|
||||||
|
|| p.peek_tok.kind !in [.name, .amp, .lsbr, .lpar]) {
|
||||||
iface_pos := p.tok.pos()
|
iface_pos := p.tok.pos()
|
||||||
mut iface_name := p.tok.lit
|
mut iface_name := p.tok.lit
|
||||||
iface_type := p.parse_type()
|
iface_type := p.parse_type()
|
||||||
|
|
Loading…
Reference in New Issue