mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: disallow using attributes on embedded structs (#15901)
This commit is contained in:
parent
1ac3f3d8dc
commit
1ff1f23d9a
@ -224,6 +224,9 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
||||
p.error_with_pos('duplicate field `$field_name`', type_pos)
|
||||
return ast.StructDecl{}
|
||||
}
|
||||
if p.tok.kind == .lsbr {
|
||||
p.error('cannot use attributes on embedded structs')
|
||||
}
|
||||
embed_field_names << field_name
|
||||
embed_types << typ
|
||||
embeds << ast.Embed{
|
||||
|
7
vlib/v/parser/tests/embeded_struct_attribute_err.out
Normal file
7
vlib/v/parser/tests/embeded_struct_attribute_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/parser/tests/embeded_struct_attribute_err.vv:8:7: error: cannot use attributes on embedded structs
|
||||
6 |
|
||||
7 | struct Button {
|
||||
8 | Size [json: size] // fmt removes [json: size]
|
||||
| ^
|
||||
9 | }
|
||||
10 |
|
14
vlib/v/parser/tests/embeded_struct_attribute_err.vv
Normal file
14
vlib/v/parser/tests/embeded_struct_attribute_err.vv
Normal file
@ -0,0 +1,14 @@
|
||||
import json
|
||||
|
||||
struct Size {
|
||||
width int
|
||||
}
|
||||
|
||||
struct Button {
|
||||
Size [json: size] // fmt removes [json: size]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := Button{}
|
||||
println(json.encode(a)) // {"size":{"width":0}}
|
||||
}
|
Loading…
Reference in New Issue
Block a user