diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index f805424411..46580faa64 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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(', ') diff --git a/vlib/v/tests/multiret_with_sumtype_test.v b/vlib/v/tests/multiret_with_sumtype_test.v new file mode 100644 index 0000000000..91eacb6688 --- /dev/null +++ b/vlib/v/tests/multiret_with_sumtype_test.v @@ -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' +}