parser: improve embedded struct parsing/better error for `Architecture []string` (#13995)

pull/14007/head
yuyi 2022-04-10 15:24:36 +08:00 committed by GitHub
parent 3571f66a82
commit 93a5d03182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,13 @@
vlib/v/checker/tests/struct_field_name_err.vv:2:2: error: field name `Architecture` cannot contain uppercase letters, use snake_case instead
1 | struct Release {
2 | Architecture []string
| ~~~~~~~~~~~~~~~~~~~~~
3 | Components []string
4 | }
vlib/v/checker/tests/struct_field_name_err.vv:3:2: error: field name `Components` cannot contain uppercase letters, use snake_case instead
1 | struct Release {
2 | Architecture []string
3 | Components []string
| ~~~~~~~~~~~~~~~~~~~~~
4 | }
5 |

View File

@ -0,0 +1,9 @@
struct Release {
Architecture []string
Components []string
}
fn main() {
r := Release{}
println(r)
}

View File

@ -184,7 +184,8 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
p.next()
is_field_volatile = true
}
is_embed := ((p.tok.lit.len > 1 && p.tok.lit[0].is_capital())
is_embed := ((p.tok.lit.len > 1 && p.tok.lit[0].is_capital()
&& (p.peek_tok.kind != .lsbr || p.peek_token(2).kind != .rsbr))
|| p.peek_tok.kind == .dot) && language == .v && p.peek_tok.kind != .key_fn
is_on_top := ast_fields.len == 0 && !(is_field_mut || is_field_global)
mut field_name := ''