From 63b41e67fab10c7c8d546e6db672b8e8c6534020 Mon Sep 17 00:00:00 2001 From: ChAoS_UnItY <43753315+ChAoSUnItY@users.noreply.github.com> Date: Fri, 4 Mar 2022 01:51:27 +0800 Subject: [PATCH] v.parser: change body_start_pos to function declaration's lcbr, resolve #13642 (#13646) --- vlib/v/parser/fn.v | 4 ++-- vlib/v/parser/tests/fn_body_start_pos.out | 3 +++ vlib/v/parser/tests/fn_body_start_pos.vv | 1 + vlib/v/parser/tests/fn_type_only_args_no_body.out | 7 +++---- vlib/v/parser/tests/fn_type_only_args_unknown_name.out | 7 +++---- 5 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 vlib/v/parser/tests/fn_body_start_pos.out create mode 100644 vlib/v/parser/tests/fn_body_start_pos.vv diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 26a663342e..0e8d2854a2 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -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 diff --git a/vlib/v/parser/tests/fn_body_start_pos.out b/vlib/v/parser/tests/fn_body_start_pos.out new file mode 100644 index 0000000000..0d7eb0107b --- /dev/null +++ b/vlib/v/parser/tests/fn_body_start_pos.out @@ -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) {} + | ^ \ No newline at end of file diff --git a/vlib/v/parser/tests/fn_body_start_pos.vv b/vlib/v/parser/tests/fn_body_start_pos.vv new file mode 100644 index 0000000000..900aca1ffe --- /dev/null +++ b/vlib/v/parser/tests/fn_body_start_pos.vv @@ -0,0 +1 @@ +fn func(int) {} \ No newline at end of file diff --git a/vlib/v/parser/tests/fn_type_only_args_no_body.out b/vlib/v/parser/tests/fn_type_only_args_no_body.out index fad0819c17..4484380de1 100644 --- a/vlib/v/parser/tests/fn_type_only_args_no_body.out +++ b/vlib/v/parser/tests/fn_type_only_args_no_body.out @@ -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 | diff --git a/vlib/v/parser/tests/fn_type_only_args_unknown_name.out b/vlib/v/parser/tests/fn_type_only_args_unknown_name.out index 1f94768f83..c79b778199 100644 --- a/vlib/v/parser/tests/fn_type_only_args_unknown_name.out +++ b/vlib/v/parser/tests/fn_type_only_args_unknown_name.out @@ -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 |