mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fn with optional of multi_return (#16046)
This commit is contained in:
parent
7f2d731d19
commit
c590c8250e
@ -4166,11 +4166,11 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
|
||||
}
|
||||
|
||||
fn (mut g Gen) concat_expr(node ast.ConcatExpr) {
|
||||
mut styp := g.typ(node.return_type)
|
||||
mut styp := g.typ(node.return_type.clear_flag(.optional).clear_flag(.result))
|
||||
if g.inside_return {
|
||||
styp = g.typ(g.fn_decl.return_type)
|
||||
styp = g.typ(g.fn_decl.return_type.clear_flag(.optional).clear_flag(.result))
|
||||
} else if g.inside_or_block {
|
||||
styp = g.typ(g.or_expr_return_type)
|
||||
styp = g.typ(g.or_expr_return_type.clear_flag(.optional).clear_flag(.result))
|
||||
}
|
||||
sym := g.table.sym(node.return_type)
|
||||
is_multi := sym.kind == .multi_return
|
||||
|
25
vlib/v/tests/fn_with_opt_or_res_of_multi_return_test.v
Normal file
25
vlib/v/tests/fn_with_opt_or_res_of_multi_return_test.v
Normal file
@ -0,0 +1,25 @@
|
||||
struct Aa {
|
||||
x string
|
||||
}
|
||||
|
||||
struct Bb {
|
||||
a int
|
||||
}
|
||||
|
||||
fn give(succ Aa) ?(Aa, Bb) {
|
||||
return match succ.x {
|
||||
'x' {
|
||||
succ, Bb{}
|
||||
}
|
||||
else {
|
||||
error('nok')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_fn_with_opt_of_multi_return() {
|
||||
res, _ := give(Aa{ x: 'x' }) or { panic('got unexpected err') }
|
||||
|
||||
assert res.x == 'x'
|
||||
println('success')
|
||||
}
|
Loading…
Reference in New Issue
Block a user