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

27 lines
386 B
Go
Raw Normal View History

fn opt_err() ?string {return error('hi')}
fn test_err(){
v := opt_err() or {
assert err == 'hi'
return
}
assert false
println(v) // suppress not used error
}
2019-07-15 17:15:34 +03:00
fn err_call(ok bool) ?int {
2019-07-24 23:41:46 +03:00
return 'sdf'
2019-07-15 17:15:34 +03:00
if !ok {
return error('Not ok!')
}
return 42
}
fn test_option_for_base_type_without_variable() {
val := err_call(true) or {
panic(err)
return
}
assert val == 42
}