mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: add a better error message, for multiple attributes, used on the same struct field (#16954)
This commit is contained in:
parent
3832f076c5
commit
41b9e513ca
7
vlib/v/checker/tests/struct_multiple_attrs_test.out
Normal file
7
vlib/v/checker/tests/struct_multiple_attrs_test.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/struct_multiple_attrs_test.vv:4:10: error: multiple attributes should be in the same [], with ; separators
|
||||
2 |
|
||||
3 | struct Test {
|
||||
4 | a int [a][b]
|
||||
| ~~
|
||||
5 | }
|
||||
6 |
|
9
vlib/v/checker/tests/struct_multiple_attrs_test.vv
Normal file
9
vlib/v/checker/tests/struct_multiple_attrs_test.vv
Normal file
@ -0,0 +1,9 @@
|
||||
module main
|
||||
|
||||
struct Test {
|
||||
a int [a][b]
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
assert true
|
||||
}
|
@ -60,6 +60,7 @@ mut:
|
||||
inside_generic_params bool // indicates if parsing between `<` and `>` of a method/function
|
||||
inside_receiver_param bool // indicates if parsing the receiver parameter inside the first `(` and `)` of a method
|
||||
inside_struct_field_decl bool
|
||||
inside_struct_attr_decl bool
|
||||
inside_map_init bool
|
||||
or_is_handled bool // ignore `or` in this expression
|
||||
builtin_mod bool // are we in the `builtin` module?
|
||||
@ -1773,6 +1774,11 @@ fn (mut p Parser) attributes() {
|
||||
p.error_with_pos('attributes cannot be empty', p.prev_tok.pos().extend(p.tok.pos()))
|
||||
return
|
||||
}
|
||||
if p.inside_struct_attr_decl && p.tok.kind == .lsbr {
|
||||
p.error_with_pos('multiple attributes should be in the same [], with ; separators',
|
||||
p.prev_tok.pos().extend(p.tok.pos()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut p Parser) parse_attr() ast.Attr {
|
||||
|
@ -268,6 +268,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
||||
// Comments after type (same line)
|
||||
comments << p.eat_comments()
|
||||
if p.tok.kind == .lsbr {
|
||||
p.inside_struct_attr_decl = true
|
||||
// attrs are stored in `p.attrs`
|
||||
p.attributes()
|
||||
for fa in p.attrs {
|
||||
@ -275,6 +276,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
||||
is_field_deprecated = true
|
||||
}
|
||||
}
|
||||
p.inside_struct_attr_decl = false
|
||||
}
|
||||
mut default_expr := ast.empty_expr
|
||||
mut has_default_expr := false
|
||||
|
Loading…
Reference in New Issue
Block a user