mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix error for returning optional (#13902)
This commit is contained in:
parent
af79c1e6ef
commit
0bf0c73a49
@ -148,7 +148,7 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) {
|
||||
if exp_is_optional && node.exprs.len > 0 {
|
||||
expr0 := node.exprs[0]
|
||||
if expr0 is ast.CallExpr {
|
||||
if expr0.or_block.kind == .propagate {
|
||||
if expr0.or_block.kind == .propagate && node.exprs.len == 1 {
|
||||
c.error('`?` is not needed, use `return ${expr0.name}()`', expr0.pos)
|
||||
}
|
||||
}
|
||||
|
14
vlib/v/tests/return_optional_test.v
Normal file
14
vlib/v/tests/return_optional_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
fn func1() ?int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fn func2() ?(int, int) {
|
||||
return func1() ?, 1
|
||||
}
|
||||
|
||||
fn test_return_optional() ? {
|
||||
a, b := func2() ?
|
||||
println('$a, $b')
|
||||
assert a == 0
|
||||
assert b == 1
|
||||
}
|
Loading…
Reference in New Issue
Block a user