mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix fn attrs with anon struct param (#17266)
This commit is contained in:
parent
4c33a92aac
commit
19ba7c5ceb
14
vlib/v/fmt/tests/anon_struct_as_param_with_fn_attrs_keep.vv
Normal file
14
vlib/v/fmt/tests/anon_struct_as_param_with_fn_attrs_keep.vv
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// foo.v
|
||||||
|
|
||||||
|
[params]
|
||||||
|
fn hello(person struct { name string }) string {
|
||||||
|
if person.name == '' {
|
||||||
|
return 'Hello World!'
|
||||||
|
} else {
|
||||||
|
return 'Hello ${person.name}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println(hello())
|
||||||
|
}
|
@ -11,7 +11,6 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
|||||||
p.top_level_statement_start()
|
p.top_level_statement_start()
|
||||||
// save attributes, they will be changed later in fields
|
// save attributes, they will be changed later in fields
|
||||||
attrs := p.attrs
|
attrs := p.attrs
|
||||||
p.attrs = []
|
|
||||||
start_pos := p.tok.pos()
|
start_pos := p.tok.pos()
|
||||||
mut is_pub := p.tok.kind == .key_pub
|
mut is_pub := p.tok.kind == .key_pub
|
||||||
if is_pub {
|
if is_pub {
|
||||||
@ -267,6 +266,8 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
|||||||
}
|
}
|
||||||
// Comments after type (same line)
|
// Comments after type (same line)
|
||||||
comments << p.eat_comments()
|
comments << p.eat_comments()
|
||||||
|
prev_attrs := p.attrs
|
||||||
|
p.attrs = []
|
||||||
if p.tok.kind == .lsbr {
|
if p.tok.kind == .lsbr {
|
||||||
p.inside_struct_attr_decl = true
|
p.inside_struct_attr_decl = true
|
||||||
// attrs are stored in `p.attrs`
|
// attrs are stored in `p.attrs`
|
||||||
@ -331,7 +332,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
|||||||
is_volatile: is_field_volatile
|
is_volatile: is_field_volatile
|
||||||
is_deprecated: is_field_deprecated
|
is_deprecated: is_field_deprecated
|
||||||
}
|
}
|
||||||
p.attrs = []
|
p.attrs = prev_attrs
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
p.top_level_statement_end()
|
p.top_level_statement_end()
|
||||||
|
Loading…
Reference in New Issue
Block a user