checker: make the misssing shared/mut modifer in fn and method calls error clearer
parent
55d9464890
commit
cc637e5ee8
|
@ -812,8 +812,8 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
||||||
} else {
|
} else {
|
||||||
if param.is_mut {
|
if param.is_mut {
|
||||||
tok := call_arg.share.str()
|
tok := call_arg.share.str()
|
||||||
c.error('`$node.name` parameter `$param.name` is `$tok`, you need to provide `$tok` e.g. `$tok arg${
|
c.error('function `$node.name` parameter `$param.name` is `$tok`, so use `$tok $call_arg.expr` instead',
|
||||||
i + 1}`', call_arg.expr.pos())
|
call_arg.expr.pos())
|
||||||
} else {
|
} else {
|
||||||
c.fail_if_unreadable(call_arg.expr, typ, 'argument')
|
c.fail_if_unreadable(call_arg.expr, typ, 'argument')
|
||||||
}
|
}
|
||||||
|
@ -1307,8 +1307,8 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||||
} else {
|
} else {
|
||||||
if param_is_mut {
|
if param_is_mut {
|
||||||
tok := arg.share.str()
|
tok := arg.share.str()
|
||||||
c.error('`$node.name` parameter `$param.name` is `$tok`, you need to provide `$tok` e.g. `$tok arg${
|
c.error('method `$node.name` parameter `$param.name` is `$tok`, so use `$tok $arg.expr` instead',
|
||||||
i + 1}`', arg.expr.pos())
|
arg.expr.pos())
|
||||||
} else {
|
} else {
|
||||||
c.fail_if_unreadable(arg.expr, got_arg_typ, 'argument')
|
c.fail_if_unreadable(arg.expr, got_arg_typ, 'argument')
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ vlib/v/checker/tests/chan_args.vv:5:19: error: cannot use `float literal` as `&f
|
||||||
| ~~~
|
| ~~~
|
||||||
6 | b := 2.5
|
6 | b := 2.5
|
||||||
7 | _ := ch.try_pop(b)
|
7 | _ := ch.try_pop(b)
|
||||||
vlib/v/checker/tests/chan_args.vv:7:18: error: `try_pop` parameter `obj` is `mut`, you need to provide `mut` e.g. `mut arg1`
|
vlib/v/checker/tests/chan_args.vv:7:18: error: method `try_pop` parameter `obj` is `mut`, so use `mut b` instead
|
||||||
5 | _ := ch.try_push(2.5)
|
5 | _ := ch.try_push(2.5)
|
||||||
6 | b := 2.5
|
6 | b := 2.5
|
||||||
7 | _ := ch.try_pop(b)
|
7 | _ := ch.try_pop(b)
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
vlib/v/checker/tests/mut_arg.vv:6:3: error: `f` parameter `par` is `mut`, you need to provide `mut` e.g. `mut arg1`
|
vlib/v/checker/tests/mut_arg.vv:6:3: error: function `f` parameter `par` is `mut`, so use `mut [3, 4]` instead
|
||||||
4 | }
|
4 | }
|
||||||
5 |
|
5 |
|
||||||
6 | f([3,4])
|
6 | f([3,4])
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
7 | mut a := [1,2]
|
7 | mut a := [1,2]
|
||||||
8 | f(a)
|
8 | f(a)
|
||||||
vlib/v/checker/tests/mut_arg.vv:8:3: error: `f` parameter `par` is `mut`, you need to provide `mut` e.g. `mut arg1`
|
vlib/v/checker/tests/mut_arg.vv:8:3: error: function `f` parameter `par` is `mut`, so use `mut a` instead
|
||||||
6 | f([3,4])
|
6 | f([3,4])
|
||||||
7 | mut a := [1,2]
|
7 | mut a := [1,2]
|
||||||
8 | f(a)
|
8 | f(a)
|
||||||
| ^
|
| ^
|
||||||
9 |
|
9 |
|
||||||
10 | g(mut [3,4])
|
10 | g(mut [3,4])
|
||||||
vlib/v/checker/tests/mut_arg.vv:10:7: error: array literal can not be modified
|
vlib/v/checker/tests/mut_arg.vv:10:7: error: array literal can not be modified
|
||||||
8 | f(a)
|
8 | f(a)
|
||||||
9 |
|
9 |
|
||||||
10 | g(mut [3,4])
|
10 | g(mut [3,4])
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
11 | g(mut a)
|
11 | g(mut a)
|
||||||
vlib/v/checker/tests/mut_arg.vv:11:7: error: `g` parameter `par` is not `mut`, `mut` is not needed`
|
vlib/v/checker/tests/mut_arg.vv:11:7: error: `g` parameter `par` is not `mut`, `mut` is not needed`
|
||||||
9 |
|
9 |
|
||||||
10 | g(mut [3,4])
|
10 | g(mut [3,4])
|
||||||
11 | g(mut a)
|
11 | g(mut a)
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
vlib/v/checker/tests/mut_interface_param_err.vv:19:10: error: `add` parameter `widget` is `mut`, you need to provide `mut` e.g. `mut arg1`
|
vlib/v/checker/tests/mut_interface_param_err.vv:19:10: error: method `add` parameter `widget` is `mut`, so use `mut btn` instead
|
||||||
17 | mut win := Window{}
|
17 | mut win := Window{}
|
||||||
18 | mut btn := Button{}
|
18 | mut btn := Button{}
|
||||||
19 | win.add(btn) // should be an error here
|
19 | win.add(btn) // should be an error here
|
||||||
|
|
Loading…
Reference in New Issue