mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix 'return none' in void optional function (#16545)
This commit is contained in:
parent
7d8c386721
commit
d257e43932
@ -93,10 +93,6 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
|
||||
if (exp_is_optional
|
||||
&& got_types_0_idx in [ast.none_type_idx, ast.error_type_idx, option_type_idx])
|
||||
|| (exp_is_result && got_types_0_idx in [ast.error_type_idx, result_type_idx]) {
|
||||
if got_types_0_idx == ast.none_type_idx && expected_type == ast.ovoid_type {
|
||||
c.error('returning `none` in functions, that have a `?` result type is not allowed anymore, either `return error(message)` or just `return` instead',
|
||||
node.pos)
|
||||
}
|
||||
return
|
||||
}
|
||||
if expected_types.len > 0 && expected_types.len != got_types.len {
|
||||
|
12
vlib/v/tests/option_void_2_test.v
Normal file
12
vlib/v/tests/option_void_2_test.v
Normal file
@ -0,0 +1,12 @@
|
||||
fn test_optional_void() {
|
||||
foo(22)?
|
||||
assert true
|
||||
}
|
||||
|
||||
fn foo(n int) ? {
|
||||
if n > 0 {
|
||||
println(n)
|
||||
} else {
|
||||
return none
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user