From f4586b1577bee988ad8f135a5ae282f53c105fff Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 30 Apr 2022 10:29:33 +0800 Subject: [PATCH] parser: make sure interface field names use uppercase letters (#14228) --- .../tests/interface_field_name_err.out | 20 +++++++++++++++++++ .../checker/tests/interface_field_name_err.vv | 8 ++++++++ vlib/v/parser/struct.v | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/interface_field_name_err.out create mode 100644 vlib/v/checker/tests/interface_field_name_err.vv diff --git a/vlib/v/checker/tests/interface_field_name_err.out b/vlib/v/checker/tests/interface_field_name_err.out new file mode 100644 index 0000000000..0b1e3bcdfc --- /dev/null +++ b/vlib/v/checker/tests/interface_field_name_err.out @@ -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 | diff --git a/vlib/v/checker/tests/interface_field_name_err.vv b/vlib/v/checker/tests/interface_field_name_err.vv new file mode 100644 index 0000000000..7d9d748c7c --- /dev/null +++ b/vlib/v/checker/tests/interface_field_name_err.vv @@ -0,0 +1,8 @@ +interface Animal { + Age int + Foo &int + Bar []string +} + +fn main() { +} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 016afd3f2f..24985e747e 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -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()