mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check method call argument type mismatch (#14496)
This commit is contained in:
parent
ba859c584b
commit
7f03b89611
@ -1461,12 +1461,10 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if got_arg_typ != ast.void_type {
|
||||
c.error('$err.msg() in argument ${i + 1} to `${left_sym.name}.$method_name`',
|
||||
arg.pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
if method.is_unsafe && !c.inside_unsafe {
|
||||
c.warn('method `${left_sym.name}.$method_name` must be called from an `unsafe` block',
|
||||
node.pos)
|
||||
|
6
vlib/v/checker/tests/method_call_arg_mismatch.out
Normal file
6
vlib/v/checker/tests/method_call_arg_mismatch.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/method_call_arg_mismatch.vv:9:10: error: `baz()` (no value) used as value in argument 1 to `Foo.bar`
|
||||
7 | fn main() {
|
||||
8 | foo := Foo{}
|
||||
9 | foo.bar(baz())
|
||||
| ~~~~~
|
||||
10 | }
|
10
vlib/v/checker/tests/method_call_arg_mismatch.vv
Normal file
10
vlib/v/checker/tests/method_call_arg_mismatch.vv
Normal file
@ -0,0 +1,10 @@
|
||||
struct Foo {}
|
||||
|
||||
fn (f Foo) bar(baz fn ()) {}
|
||||
|
||||
fn baz() {}
|
||||
|
||||
fn main() {
|
||||
foo := Foo{}
|
||||
foo.bar(baz())
|
||||
}
|
Loading…
Reference in New Issue
Block a user