mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
7fe794a974
commit
97a726b188
@ -6115,11 +6115,8 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
|
||||
}
|
||||
if or_block.kind == .block {
|
||||
g.or_expr_return_type = return_type.clear_flags(.option, .result)
|
||||
if g.inside_or_block {
|
||||
g.writeln('\terr = ${cvar_name}.err;')
|
||||
} else {
|
||||
g.writeln('\tIError err = ${cvar_name}.err;')
|
||||
}
|
||||
|
||||
g.inside_or_block = true
|
||||
defer {
|
||||
g.inside_or_block = false
|
||||
|
18
vlib/v/tests/nested_or_expr_call_test.v
Normal file
18
vlib/v/tests/nested_or_expr_call_test.v
Normal file
@ -0,0 +1,18 @@
|
||||
fn get_name() !string {
|
||||
return error('failed')
|
||||
}
|
||||
|
||||
fn test_nested_or_expr_call() {
|
||||
uid_map := map[int]string{}
|
||||
uid := 2
|
||||
username := if uid <= 0 {
|
||||
'unknown'
|
||||
} else {
|
||||
uid_map[uid] or {
|
||||
name := get_name() or { 'unknown' }
|
||||
name
|
||||
}
|
||||
}
|
||||
assert username == 'unknown'
|
||||
println('${uid} is ${username}')
|
||||
}
|
Loading…
Reference in New Issue
Block a user