v.parser: change body_start_pos to function declaration's lcbr, resolve #13642 (#13646)

pull/13652/head
ChAoS_UnItY 2022-03-04 01:51:27 +08:00 committed by GitHub
parent 9cc73fd0f8
commit 63b41e67fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 10 deletions

View File

@ -466,10 +466,10 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
// Body
p.cur_fn_name = name
mut stmts := []ast.Stmt{}
body_start_pos := p.peek_tok.pos()
body_start_pos := p.tok.pos()
if p.tok.kind == .lcbr {
if language != .v && language != .js {
p.error_with_pos('interop functions cannot have a body', p.tok.pos())
p.error_with_pos('interop functions cannot have a body', body_start_pos)
}
p.inside_fn = true
p.inside_unsafe_fn = is_unsafe

View File

@ -0,0 +1,3 @@
vlib/v/parser/tests/fn_body_start_pos.vv:1:14: error: functions with type only args can not have bodies
1 | fn func(int) {}
| ^

View File

@ -0,0 +1 @@
fn func(int) {}

View File

@ -1,6 +1,5 @@
vlib/v/parser/tests/fn_type_only_args_no_body.vv:2:1: error: functions with type only args can not have bodies
vlib/v/parser/tests/fn_type_only_args_no_body.vv:1:14: error: functions with type only args can not have bodies
1 | fn test(int) {
| ^
2 | }
| ^
3 |
4 | fn main() {
3 |

View File

@ -1,6 +1,5 @@
vlib/v/parser/tests/fn_type_only_args_unknown_name.vv:2:1: error: functions with type only args can not have bodies
vlib/v/parser/tests/fn_type_only_args_unknown_name.vv:1:16: error: functions with type only args can not have bodies
1 | fn test(param) {
| ^
2 | }
| ^
3 |
4 | fn main() {
3 |