mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check fn type mismatch of return result type fn (#16269)
This commit is contained in:
parent
c3e209a634
commit
339bd0c4b5
@ -381,6 +381,9 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym
|
||||
if got_fn.return_type.has_flag(.optional) != exp_fn.return_type.has_flag(.optional) {
|
||||
return false
|
||||
}
|
||||
if got_fn.return_type.has_flag(.result) != exp_fn.return_type.has_flag(.result) {
|
||||
return false
|
||||
}
|
||||
if !c.check_basic(got_fn.return_type, exp_fn.return_type) {
|
||||
return false
|
||||
}
|
||||
|
6
vlib/v/checker/tests/return_result_fn_mismatch.out
Normal file
6
vlib/v/checker/tests/return_result_fn_mismatch.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/return_result_fn_mismatch.vv:15:10: error: cannot use `fn ()` as `fn () !` in argument 1 to `do_test`
|
||||
13 | foo() or { return }
|
||||
14 | }
|
||||
15 | do_test(test)
|
||||
| ~~~~
|
||||
16 | }
|
16
vlib/v/checker/tests/return_result_fn_mismatch.vv
Normal file
16
vlib/v/checker/tests/return_result_fn_mismatch.vv
Normal file
@ -0,0 +1,16 @@
|
||||
type AnonOptionalFun = fn () !
|
||||
|
||||
// do_test is used to test functionality
|
||||
pub fn do_test(cb AnonOptionalFun) {
|
||||
cb() or { panic(err) }
|
||||
}
|
||||
|
||||
fn foo () ! {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test := fn () {
|
||||
foo() or { return }
|
||||
}
|
||||
do_test(test)
|
||||
}
|
Loading…
Reference in New Issue
Block a user