mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix fn attributes empty error
This commit is contained in:
parent
0d1e5abc41
commit
90f07eb64a
5
vlib/v/checker/tests/fn_attributes_empty_err.out
Normal file
5
vlib/v/checker/tests/fn_attributes_empty_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/fn_attributes_empty_err.v:1:1: error: attributes cannot be empty
|
||||
1 | [] fn tt() {
|
||||
| ~~
|
||||
2 | println('text')
|
||||
3 | }
|
6
vlib/v/checker/tests/fn_attributes_empty_err.vv
Normal file
6
vlib/v/checker/tests/fn_attributes_empty_err.vv
Normal file
@ -0,0 +1,6 @@
|
||||
[] fn tt() {
|
||||
println('text')
|
||||
}
|
||||
fn main() {
|
||||
tt()
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
vlib/v/checker/tests/multiple_fn_attributes.v:2:1: error: multiple attributes detected
|
||||
vlib/v/checker/tests/multiple_fn_attributes.v:1:1: error: multiple attributes detected
|
||||
1 | [inline;deprecated]
|
||||
| ~~~~~~~~~~~~~~~~~~~
|
||||
2 | fn foo(name string) string {}
|
||||
| ~~
|
@ -407,9 +407,14 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
|
||||
}
|
||||
}
|
||||
.lsbr {
|
||||
start_pos := p.tok.position()
|
||||
attrs := p.attributes()
|
||||
if attrs.len > 1 {
|
||||
p.error('multiple attributes detected')
|
||||
end_pos := p.tok.position()
|
||||
p.error_with_pos('multiple attributes detected', start_pos.extend(end_pos))
|
||||
} else if attrs.len == 0 {
|
||||
end_pos := p.tok.position()
|
||||
p.error_with_pos('attributes cannot be empty', start_pos.extend(end_pos))
|
||||
}
|
||||
return attrs[0]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user