diff --git a/vlib/v/checker/return.v b/vlib/v/checker/return.v index 82ac175db0..a8c92f7a98 100644 --- a/vlib/v/checker/return.v +++ b/vlib/v/checker/return.v @@ -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) } } diff --git a/vlib/v/tests/return_optional_test.v b/vlib/v/tests/return_optional_test.v new file mode 100644 index 0000000000..9e80a5bbfe --- /dev/null +++ b/vlib/v/tests/return_optional_test.v @@ -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 +}