mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix multiple return with sumtype (#12930)
This commit is contained in:
parent
6a4fa6096e
commit
6eb44f472a
@ -4763,8 +4763,8 @@ fn (mut g Gen) return_stmt(node ast.Return) {
|
||||
g.writeln('return $tmpvar;')
|
||||
return
|
||||
}
|
||||
// typ_sym := g.table.sym(g.fn_decl.return_type)
|
||||
// mr_info := typ_sym.info as ast.MultiReturn
|
||||
typ_sym := g.table.sym(g.fn_decl.return_type)
|
||||
mr_info := typ_sym.info as ast.MultiReturn
|
||||
mut styp := ''
|
||||
if fn_return_is_optional {
|
||||
g.writeln('$ret_typ $tmpvar;')
|
||||
@ -4826,7 +4826,11 @@ fn (mut g Gen) return_stmt(node ast.Return) {
|
||||
if expr.is_auto_deref_var() {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(expr)
|
||||
if g.table.sym(mr_info.types[i]).kind in [.sum_type, .interface_] {
|
||||
g.expr_with_cast(expr, node.types[i], mr_info.types[i])
|
||||
} else {
|
||||
g.expr(expr)
|
||||
}
|
||||
arg_idx++
|
||||
if i < node.exprs.len - 1 {
|
||||
g.write(', ')
|
||||
|
15
vlib/v/tests/multiret_with_sumtype_test.v
Normal file
15
vlib/v/tests/multiret_with_sumtype_test.v
Normal file
@ -0,0 +1,15 @@
|
||||
module main
|
||||
|
||||
type Abc = int | rune | string | u32
|
||||
|
||||
fn cyz() (Abc, string) {
|
||||
return 'a', 'b'
|
||||
}
|
||||
|
||||
fn test_multiret_with_sumtype() {
|
||||
x, y := cyz()
|
||||
println(x)
|
||||
println(y)
|
||||
assert x == Abc('a')
|
||||
assert y == 'b'
|
||||
}
|
Loading…
Reference in New Issue
Block a user