From 0c249fa040c47b560c2ca21f0f32a0777c224b38 Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 21 Jan 2021 19:01:40 +0900 Subject: [PATCH] parser: improve anon fn pos (#8210) --- vlib/v/checker/tests/array_filter_anon_fn_err_a.out | 4 ++-- vlib/v/checker/tests/array_filter_anon_fn_err_b.out | 4 ++-- vlib/v/checker/tests/array_map_anon_fn_err_a.out | 4 ++-- vlib/v/checker/tests/array_map_anon_fn_err_b.out | 2 +- vlib/v/checker/tests/array_map_anon_fn_err_c.out | 2 +- vlib/v/checker/tests/fn_var.out | 2 +- vlib/v/parser/fn.v | 5 ++--- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/vlib/v/checker/tests/array_filter_anon_fn_err_a.out b/vlib/v/checker/tests/array_filter_anon_fn_err_a.out index a8c77d9d0c..afb50458f3 100644 --- a/vlib/v/checker/tests/array_filter_anon_fn_err_a.out +++ b/vlib/v/checker/tests/array_filter_anon_fn_err_a.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/array_filter_anon_fn_err_a.vv:2:24: error: function needs exactly 1 argument 1 | fn main() { 2 | a := [1,2,3,4].filter(fn(a int, b int) bool { return a > 0 }) - | ~~ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | println(a) - 4 | } \ No newline at end of file + 4 | } diff --git a/vlib/v/checker/tests/array_filter_anon_fn_err_b.out b/vlib/v/checker/tests/array_filter_anon_fn_err_b.out index b08034a71d..8386573020 100644 --- a/vlib/v/checker/tests/array_filter_anon_fn_err_b.out +++ b/vlib/v/checker/tests/array_filter_anon_fn_err_b.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/array_filter_anon_fn_err_b.vv:2:24: error: type mismatch, should use `fn(a int) bool {...}` 1 | fn main() { 2 | a := [1,2,3,4].filter(fn(a string) bool { return a.len > 0 }) - | ~~ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | println(a) - 4 | } \ No newline at end of file + 4 | } diff --git a/vlib/v/checker/tests/array_map_anon_fn_err_a.out b/vlib/v/checker/tests/array_map_anon_fn_err_a.out index 156a7d711b..cf36f5316e 100644 --- a/vlib/v/checker/tests/array_map_anon_fn_err_a.out +++ b/vlib/v/checker/tests/array_map_anon_fn_err_a.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/array_map_anon_fn_err_a.vv:2:21: error: function needs exactly 1 argument 1 | fn main() { 2 | a := [1,2,3,4].map(fn(a int, b int) int {return a + b}) - | ~~ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | println(a) - 4 | } \ No newline at end of file + 4 | } diff --git a/vlib/v/checker/tests/array_map_anon_fn_err_b.out b/vlib/v/checker/tests/array_map_anon_fn_err_b.out index f08ab7de5b..e07dda8241 100644 --- a/vlib/v/checker/tests/array_map_anon_fn_err_b.out +++ b/vlib/v/checker/tests/array_map_anon_fn_err_b.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/array_map_anon_fn_err_b.vv:2:21: error: type mismatch, should use `fn(a int) T {...}` 1 | fn main() { 2 | a := [1,2,3,4].map(fn(a string) string { return a }) - | ~~ + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | println(a) 4 | } diff --git a/vlib/v/checker/tests/array_map_anon_fn_err_c.out b/vlib/v/checker/tests/array_map_anon_fn_err_c.out index 6e92fbd4c2..55e51b01d3 100644 --- a/vlib/v/checker/tests/array_map_anon_fn_err_c.out +++ b/vlib/v/checker/tests/array_map_anon_fn_err_c.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/array_map_anon_fn_err_c.vv:2:21: error: type mismatch, should use `fn(a int) T {...}` 1 | fn main() { 2 | a := [1,2,3,4].map(fn(a string) {}) - | ~~ + | ~~~~~~~~~~~~~~~ 3 | println(a) 4 | } diff --git a/vlib/v/checker/tests/fn_var.out b/vlib/v/checker/tests/fn_var.out index b65af8fa0c..ad42c57e6b 100644 --- a/vlib/v/checker/tests/fn_var.out +++ b/vlib/v/checker/tests/fn_var.out @@ -14,4 +14,4 @@ vlib/v/checker/tests/fn_var.vv:5:5: error: cannot assign to `f`: expected `fn (i 3 | mut p := &f 4 | p = &[f] 5 | f = fn(mut a []int) {} - | ~~ + | ~~~~~~~~~~~~~~~~~~ diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index e387258301..8ac35a5186 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -439,7 +439,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { } fn (mut p Parser) anon_fn() ast.AnonFn { - mut pos := p.tok.position() + pos := p.tok.position() p.check(.key_fn) if p.pref.is_script && p.tok.kind == .name { p.error_with_pos('function declarations in script mode should be before all script statements', @@ -491,7 +491,6 @@ fn (mut p Parser) anon_fn() ast.AnonFn { idx := p.table.find_or_register_fn_type(p.mod, func, true, false) typ := table.new_type(idx) // name := p.table.get_type_name(typ) - pos.update_last_line(p.prev_tok.line_nr) return ast.AnonFn{ decl: ast.FnDecl{ name: name @@ -503,7 +502,7 @@ fn (mut p Parser) anon_fn() ast.AnonFn { is_method: false is_anon: true no_body: no_body - pos: pos + pos: pos.extend(p.prev_tok.position()) file: p.file_name scope: p.scope }