1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: optionals default value

This commit is contained in:
joe-conigliaro
2019-11-04 10:38:49 +11:00
committed by Alexander Medvednikov
parent 4e64a58ac1
commit df5faf35e5
14 changed files with 86 additions and 26 deletions

View File

@ -46,6 +46,8 @@ fn test_defer_early_exit() {
fn test_defer_option() {
mut ok := Num{0}
set_num_opt(mut ok)
set_num_opt(mut ok) or {
assert false
}
assert ok.val == 1
}

View File

@ -58,3 +58,15 @@ fn test_if_opt() {
assert 1 == 1
println('nice')
}
fn for_opt_default() ?string {
return error('awww')
}
fn test_opt_default() {
a := for_opt_default() or {
// panic(err)
'default'
}
assert a == 'default'
}