checker: check method call argument type mismatch (#14496)

yuyi 2022-05-23 03:16:46 +08:00 committed by Jef Roosens
parent 86ba683536
commit 880223c2dd
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 18 additions and 4 deletions

View File

@ -1461,10 +1461,8 @@ 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)
}
c.error('$err.msg() in argument ${i + 1} to `${left_sym.name}.$method_name`',
arg.pos)
}
}
if method.is_unsafe && !c.inside_unsafe {

View 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 | }

View File

@ -0,0 +1,10 @@
struct Foo {}
fn (f Foo) bar(baz fn ()) {}
fn baz() {}
fn main() {
foo := Foo{}
foo.bar(baz())
}