mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: improve error message of fn args mismatch (#15550)
This commit is contained in:
parent
329670431b
commit
f45042fa09
@ -389,7 +389,12 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym
|
|||||||
if exp_arg_is_ptr != got_arg_is_ptr {
|
if exp_arg_is_ptr != got_arg_is_ptr {
|
||||||
exp_arg_pointedness := if exp_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' }
|
exp_arg_pointedness := if exp_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' }
|
||||||
got_arg_pointedness := if got_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' }
|
got_arg_pointedness := if got_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' }
|
||||||
c.add_error_detail('`$exp_fn.name`\'s expected fn argument: `$exp_arg.name` is $exp_arg_pointedness, but the passed fn argument: `$got_arg.name` is $got_arg_pointedness')
|
if exp_fn.name.len == 0 {
|
||||||
|
c.add_error_detail('expected argument ${i + 1} to be $exp_arg_pointedness, but the passed argument ${
|
||||||
|
i + 1} is $got_arg_pointedness')
|
||||||
|
} else {
|
||||||
|
c.add_error_detail('`$exp_fn.name`\'s expected argument `$exp_arg.name` to be $exp_arg_pointedness, but the passed argument `$got_arg.name` is $got_arg_pointedness')
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
} else if exp_arg_is_ptr && got_arg_is_ptr {
|
} else if exp_arg_is_ptr && got_arg_is_ptr {
|
||||||
continue
|
continue
|
||||||
|
@ -12,7 +12,7 @@ vlib/v/checker/tests/array_sort_with_compare_err.vv:4:26: error: cannot use `fn
|
|||||||
| ~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~
|
||||||
5 | println(names)
|
5 | println(names)
|
||||||
6 |
|
6 |
|
||||||
Details: ``'s expected fn argument: `` is a pointer, but the passed fn argument: `a` is NOT a pointer
|
Details: expected argument 1 to be a pointer, but the passed argument 1 is NOT a pointer
|
||||||
vlib/v/checker/tests/array_sort_with_compare_err.vv:7:26: error: cannot use `int literal` as `fn (voidptr, voidptr) int` in argument 1 to `[]string.sort_with_compare`
|
vlib/v/checker/tests/array_sort_with_compare_err.vv:7:26: error: cannot use `int literal` as `fn (voidptr, voidptr) int` in argument 1 to `[]string.sort_with_compare`
|
||||||
5 | println(names)
|
5 | println(names)
|
||||||
6 |
|
6 |
|
||||||
|
@ -19,7 +19,7 @@ vlib/v/checker/tests/fn_args.vv:11:6: error: cannot use `fn (&int)` as `fn (int)
|
|||||||
| ~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~
|
||||||
12 | fun(fn (ii ...int) {})
|
12 | fun(fn (ii ...int) {})
|
||||||
13 | }
|
13 | }
|
||||||
Details: ``'s expected fn argument: `` is NOT a pointer, but the passed fn argument: `i` is a pointer
|
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
|
||||||
vlib/v/checker/tests/fn_args.vv:12:6: error: cannot use `fn (...int)` as `fn (int)` in argument 1 to `fun`
|
vlib/v/checker/tests/fn_args.vv:12:6: error: cannot use `fn (...int)` as `fn (int)` in argument 1 to `fun`
|
||||||
10 | arr([5]!)
|
10 | arr([5]!)
|
||||||
11 | fun(fn (i &int) {})
|
11 | fun(fn (i &int) {})
|
||||||
|
@ -5,7 +5,7 @@ vlib/v/checker/tests/non_matching_functional_args.vv:27:6: error: cannot use `fn
|
|||||||
| ~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
28 | t.rename()
|
28 | t.rename()
|
||||||
29 | println(t.name)
|
29 | println(t.name)
|
||||||
Details: `main.MyFn`'s expected fn argument: `zzzz` is NOT a pointer, but the passed fn argument: `t` is a pointer
|
Details: `main.MyFn`'s expected argument `zzzz` to be NOT a pointer, but the passed argument `t` is a pointer
|
||||||
vlib/v/checker/tests/non_matching_functional_args.vv:31:6: error: cannot use `fn (mut Table)` as `fn (Table)` in argument 1 to `sum`
|
vlib/v/checker/tests/non_matching_functional_args.vv:31:6: error: cannot use `fn (mut Table)` as `fn (Table)` in argument 1 to `sum`
|
||||||
29 | println(t.name)
|
29 | println(t.name)
|
||||||
30 | })
|
30 | })
|
||||||
@ -13,4 +13,4 @@ vlib/v/checker/tests/non_matching_functional_args.vv:31:6: error: cannot use `fn
|
|||||||
| ~~~
|
| ~~~
|
||||||
32 | sum(yyy)
|
32 | sum(yyy)
|
||||||
33 | }
|
33 | }
|
||||||
Details: `main.MyFn`'s expected fn argument: `zzzz` is NOT a pointer, but the passed fn argument: `mytable` is a pointer
|
Details: `main.MyFn`'s expected argument `zzzz` to be NOT a pointer, but the passed argument `mytable` is a pointer
|
||||||
|
@ -19,7 +19,7 @@ vlib/v/checker/tests/struct_field_type_err.vv:14:3: error: cannot assign to fiel
|
|||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
15 | f2: fn (v voidptr) {}
|
15 | f2: fn (v voidptr) {}
|
||||||
16 | data: true
|
16 | data: true
|
||||||
Details: ``'s expected fn argument: `` is a pointer, but the passed fn argument: `v` is NOT a pointer
|
Details: expected argument 1 to be a pointer, but the passed argument 1 is NOT a pointer
|
||||||
vlib/v/checker/tests/struct_field_type_err.vv:15:3: error: cannot assign to field `f2`: expected `fn (...voidptr)`, not `fn (voidptr)`
|
vlib/v/checker/tests/struct_field_type_err.vv:15:3: error: cannot assign to field `f2`: expected `fn (...voidptr)`, not `fn (voidptr)`
|
||||||
13 | b: 0
|
13 | b: 0
|
||||||
14 | f1: fn (v ...voidptr) {}
|
14 | f1: fn (v ...voidptr) {}
|
||||||
@ -27,7 +27,7 @@ vlib/v/checker/tests/struct_field_type_err.vv:15:3: error: cannot assign to fiel
|
|||||||
| ~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
16 | data: true
|
16 | data: true
|
||||||
17 | }
|
17 | }
|
||||||
Details: ``'s expected fn argument: `` is NOT a pointer, but the passed fn argument: `v` is a pointer
|
Details: expected argument 1 to be NOT a pointer, but the passed argument 1 is a pointer
|
||||||
vlib/v/checker/tests/struct_field_type_err.vv:16:3: error: cannot assign to field `data`: expected `&Data`, not `bool`
|
vlib/v/checker/tests/struct_field_type_err.vv:16:3: error: cannot assign to field `data`: expected `&Data`, not `bool`
|
||||||
14 | f1: fn (v ...voidptr) {}
|
14 | f1: fn (v ...voidptr) {}
|
||||||
15 | f2: fn (v voidptr) {}
|
15 | f2: fn (v voidptr) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user