parser: make sure interface field names use uppercase letters (#14228)

master
yuyi 2022-04-30 10:29:33 +08:00 committed by GitHub
parent 08fd0ce0de
commit cd30b6ea82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View File

@ -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 |

View File

@ -0,0 +1,8 @@
interface Animal {
Age int
Foo &int
Bar []string
}
fn main() {
}

View File

@ -517,7 +517,8 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
mut ifaces := []ast.InterfaceEmbedding{}
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()
&& 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()
mut iface_name := p.tok.lit
iface_type := p.parse_type()