mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix checking fn prototype mismatch (#11369)
This commit is contained in:
parent
939a6417ce
commit
67ab5b858b
@ -164,8 +164,10 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym
|
||||
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')
|
||||
return false
|
||||
} else if exp_arg_is_ptr && got_arg_is_ptr {
|
||||
continue
|
||||
}
|
||||
if !c.check_basic(got_arg.typ, exp_arg.typ) {
|
||||
if got_arg.typ != exp_arg.typ {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
7
vlib/v/checker/tests/fn_type_mismatch.out
Normal file
7
vlib/v/checker/tests/fn_type_mismatch.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/fn_type_mismatch.vv:11:15: error: invalid array element: expected `fn (int, int) f32`, not `fn (f32, f32) f32`
|
||||
9 |
|
||||
10 | fn main() {
|
||||
11 | fns := [add, div]
|
||||
| ~~~
|
||||
12 | println(fns[0](10.0, 5.0))
|
||||
13 | println(fns[1](10.0, 5.0))
|
14
vlib/v/checker/tests/fn_type_mismatch.vv
Normal file
14
vlib/v/checker/tests/fn_type_mismatch.vv
Normal file
@ -0,0 +1,14 @@
|
||||
fn add(a int, b int) f32 {
|
||||
return (a + b)
|
||||
}
|
||||
|
||||
fn div(a f32, b f32) f32 {
|
||||
println('div: $a $b')
|
||||
return (a / b)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fns := [add, div]
|
||||
println(fns[0](10.0, 5.0))
|
||||
println(fns[1](10.0, 5.0))
|
||||
}
|
Loading…
Reference in New Issue
Block a user