checker: fix error for returning optional (#13902)
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 {
|
if exp_is_optional && node.exprs.len > 0 {
|
||||||
expr0 := node.exprs[0]
|
expr0 := node.exprs[0]
|
||||||
if expr0 is ast.CallExpr {
|
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)
|
c.error('`?` is not needed, use `return ${expr0.name}()`', expr0.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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