1
0
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:
yuyi 2022-10-12 14:44:15 +08:00 committed by GitHub
parent 7f2d731d19
commit c590c8250e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -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

View 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')
}