Skip to content

Commit d257e43

Browse files
authored
checker: fix 'return none' in void optional function (#16545)
1 parent 7d8c386 commit d257e43

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

vlib/v/checker/return.v

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
9393
if (exp_is_optional
9494
&& got_types_0_idx in [ast.none_type_idx, ast.error_type_idx, option_type_idx])
9595
|| (exp_is_result && got_types_0_idx in [ast.error_type_idx, result_type_idx]) {
96-
if got_types_0_idx == ast.none_type_idx && expected_type == ast.ovoid_type {
97-
c.error('returning `none` in functions, that have a `?` result type is not allowed anymore, either `return error(message)` or just `return` instead',
98-
node.pos)
99-
}
10096
return
10197
}
10298
if expected_types.len > 0 && expected_types.len != got_types.len {

vlib/v/tests/option_void_2_test.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn test_optional_void() {
2+
foo(22)?
3+
assert true
4+
}
5+
6+
fn foo(n int) ? {
7+
if n > 0 {
8+
println(n)
9+
} else {
10+
return none
11+
}
12+
}

0 commit comments

Comments
 (0)