v/vlib/v/checker/tests/expression_should_return_an...

32 lines
435 B
V

fn return_optional(fail bool) ?string {
if fail {
return error('nope')
}
return 'foo'
}
fn return_string() string {
return 'foo'
}
fn main() {
// works
if r := return_optional(false) {
println(r)
}
// works
if r := return_optional(false) {
println(r)
} else {
println(err)
}
// works
return_optional(true) or {
println(err)
}
// should be an checker error:
if x := return_string() {
println('x: $x')
}
}