mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add a missing return regression test for if branches too
This commit is contained in:
parent
ebfd259333
commit
dd1717af34
12
vlib/v/checker/tests/return_missing_if_else_simple.out
Normal file
12
vlib/v/checker/tests/return_missing_if_else_simple.out
Normal file
@ -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
|
35
vlib/v/checker/tests/return_missing_if_else_simple.vv
Normal file
35
vlib/v/checker/tests/return_missing_if_else_simple.vv
Normal file
@ -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())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user