mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: make optionals work with multi return
This commit is contained in:
@ -144,3 +144,21 @@ fn test_opt_ptr() {
|
||||
println('`$r2` should be none')
|
||||
assert false
|
||||
}
|
||||
|
||||
fn multi_return_opt(err bool) ?(string, string) {
|
||||
if err {
|
||||
return error('oops')
|
||||
}
|
||||
return 'hello', 'v'
|
||||
}
|
||||
|
||||
fn test_multi_return_opt() {
|
||||
a, b := multi_return_opt(false) or {
|
||||
panic(err)
|
||||
}
|
||||
assert a == 'hello' && b == 'v'
|
||||
_, _ := multi_return_opt(true) or {
|
||||
assert err == 'oops'
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user