0 commits 0 issues 0 pull requests 0 contributors 0 branches 0 releases
Additions: 10 Deletions: 13
vlib/v/checker/fn.v
1 // c.warn('use `value in arr` instead of `arr.contains(value)`', node.pos)
2 if node.args.len != 1 {
3 c.error('`.contains()` expected 1 argument, but got $node.args.len', node.pos)
4- } else {
5- arg_typ := ast.mktyp(c.expr(node.args[0].expr))
6- elem_typ_str := c.table.type_to_str(elem_typ)
7- arg_typ_str := c.table.type_to_str(arg_typ)
8- if !left_sym.has_method('contains') && elem_typ_str != arg_typ_str {
9- c.error('`.contains()` expected `$elem_typ_str` argument, but got `$arg_typ_str`',
10- node.pos)
11+ } else if !left_sym.has_method('contains') {
12+ arg_typ := c.expr(node.args[0].expr)
13+ c.check_expected_call_arg(arg_typ, elem_typ, node.language, node.args[0]) or {
14+ c.error('$err.msg() in argument 1 to `.contains()`', node.args[0].pos)
15 }
16 }
17 node.return_type = ast.bool_type
18
vlib/v/checker/tests/array_contains_args_err.out
1-vlib/v/checker/tests/array_contains_args_err.vv:3:17: error: `.contains()` expected `int` argument, but got `[]int`
2+vlib/v/checker/tests/array_contains_args_err.vv:3:26: error: cannot use `[]int` as `int` in argument 1 to `.contains()`
3 1 | fn main() {
4 2 | arr := [0]
5 3 | mut ret := [0].contains([0])
6- | ~~~~~~~~~~~~~
7+ | ~~~
8 4 | ret = [0].contains()
9 5 | ret = [0, 1, 2].contains(0, 1, 2)
10 vlib/v/checker/tests/array_contains_args_err.vv:4:12: error: `.contains()` expected 1 argument, but got 0
11 | ~~~~~~~~~~~~~~~~~
12 6 | ret = [0].contains('a')
13 7 | ret = [0].contains(arr)
14-vlib/v/checker/tests/array_contains_args_err.vv:6:12: error: `.contains()` expected `int` argument, but got `string`
15+vlib/v/checker/tests/array_contains_args_err.vv:6:21: error: cannot use `string` as `int` in argument 1 to `.contains()`
16 4 | ret = [0].contains()
17 5 | ret = [0, 1, 2].contains(0, 1, 2)
18 6 | ret = [0].contains('a')
19- | ~~~~~~~~~~~~~
20+ | ~~~
21 7 | ret = [0].contains(arr)
22 8 | println(ret)
23-vlib/v/checker/tests/array_contains_args_err.vv:7:12: error: `.contains()` expected `int` argument, but got `[]int`
24+vlib/v/checker/tests/array_contains_args_err.vv:7:21: error: cannot use `[]int` as `int` in argument 1 to `.contains()`
25 5 | ret = [0, 1, 2].contains(0, 1, 2)
26 6 | ret = [0].contains('a')
27 7 | ret = [0].contains(arr)
28- | ~~~~~~~~~~~~~
29+ | ~~~
30 8 | println(ret)
31 9 | }
32