diff --git a/vlib/v/checker/tests/return_missing_if_else_simple.out b/vlib/v/checker/tests/return_missing_if_else_simple.out new file mode 100644 index 0000000000..41eb21bee6 --- /dev/null +++ b/vlib/v/checker/tests/return_missing_if_else_simple.out @@ -0,0 +1,12 @@ +vlib/v/checker/tests/return_missing_if_else_simple.vv:1:1: error: missing return at end of function `if_no_returns` + 1 | fn if_no_returns() int { + | ~~~~~~~~~~~~~~~~~~~~~~ + 2 | if true { + 3 | println('no return in then') +vlib/v/checker/tests/return_missing_if_else_simple.vv:10:1: error: missing return at end of function `if_no_return_in_else` + 8 | } + 9 | + 10 | fn if_no_return_in_else() int { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 11 | if true { + 12 | return 123 diff --git a/vlib/v/checker/tests/return_missing_if_else_simple.vv b/vlib/v/checker/tests/return_missing_if_else_simple.vv new file mode 100644 index 0000000000..802a7d984d --- /dev/null +++ b/vlib/v/checker/tests/return_missing_if_else_simple.vv @@ -0,0 +1,35 @@ +fn if_no_returns() int { + if true { + println('no return in then') + } else { + println('no return in else') + } + println('hello') +} + +fn if_no_return_in_else() int { + if true { + return 123 + } else { + println('no return in else') + } + println('hello') +} + +fn if_returns_in_both_branches() int { + // The if here always returns, so the function + // returns too: + if true { + return 123 + } else { + return 456 + } + // TODO: should produce a warning/error about a statement after a return. + println('hello') +} + +fn main() { + println(if_no_returns()) + println(if_no_return_in_else()) + println(if_returns_in_both_branches()) +}