mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add a test for fn call arg of fn pointer mismatch (#15757)
This commit is contained in:
parent
fd1b3fc861
commit
ea4152ee14
7
vlib/v/checker/tests/fn_call_arg_mismatch_err_d.out
Normal file
7
vlib/v/checker/tests/fn_call_arg_mismatch_err_d.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/fn_call_arg_mismatch_err_d.vv:17:26: error: cannot use `fn (string) f64` as `fn (string) ?Flag` in argument 2 to `parse_option`
|
||||||
|
15 |
|
||||||
|
16 | fn main() {
|
||||||
|
17 | t := parse_option('45', parse_percent)?
|
||||||
|
| ~~~~~~~~~~~~~
|
||||||
|
18 | println(t)
|
||||||
|
19 | }
|
19
vlib/v/checker/tests/fn_call_arg_mismatch_err_d.vv
Normal file
19
vlib/v/checker/tests/fn_call_arg_mismatch_err_d.vv
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
type Flag = bool | f64 | int | string
|
||||||
|
|
||||||
|
fn parse_percent(value string) f64 {
|
||||||
|
f_val := value.f64()
|
||||||
|
if f_val >= 0 && f_val <= 100 {
|
||||||
|
return f_val
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_option(str string, validator fn (string) ?Flag) ?Flag {
|
||||||
|
return validator(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
t := parse_option('45', parse_percent)?
|
||||||
|
println(t)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user