parser: check struct embed with wrong position (#19245)

This commit is contained in:
yuyi 2023-08-31 17:15:35 +08:00 committed by GitHub
parent 6fb4a481f8
commit e414b54f68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

View File

@ -8,8 +8,8 @@ struct User {
}
struct FamousUser {
pub:
User
pub:
aka string
}

View File

@ -197,7 +197,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
&& (p.peek_tok.line_nr != p.tok.line_nr || p.peek_tok.kind !in [.name, .amp])
&& (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)
is_on_top := ast_fields.len == 0 && !(is_field_pub || is_field_mut || is_field_global)
mut field_name := ''
mut typ := ast.Type(0)
mut type_pos := token.Pos{}

View File

@ -0,0 +1,7 @@
vlib/v/parser/tests/struct_embed_wrong_pos_in_pub_err.vv:6:5: error: struct embedding must be declared at the beginning of the struct body
4 | pub struct ThreadSafeLog {
5 | pub:
6 | Log
| ~~~
7 | pub mut:
8 | mu Xyz

View File

@ -0,0 +1,11 @@
struct Log {}
struct Xyz {}
pub struct ThreadSafeLog {
pub:
Log
pub mut:
mu Xyz
}
fn main() {}