diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index 7d339b52c4..4e867533ad 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -521,7 +521,6 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) { fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Type) { // multi return // TODO Handle in if_expr - is_opt := return_type.has_flag(.option) || return_type.has_flag(.result) mr_var_name := 'mr_${node.pos.pos}' mr_styp := g.typ(return_type.clear_flag(.option).clear_flag(.result)) g.write('${mr_styp} ${mr_var_name} = ') @@ -551,34 +550,16 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ g.expr(lx) noscan := if is_auto_heap { g.check_noscan(return_type) } else { '' } if g.is_arraymap_set { - if is_opt { - mr_base_styp := g.base_type(return_type) - if is_auto_heap { - g.writeln('HEAP${noscan}(${mr_base_styp}, ${mr_var_name}.arg${i}) });') - } else { - g.writeln('${mr_var_name}.arg${i} });') - } + if is_auto_heap { + g.writeln('HEAP${noscan}(${styp}, ${mr_var_name}.arg${i}) });') } else { - if is_auto_heap { - g.writeln('HEAP${noscan}(${styp}, ${mr_var_name}.arg${i}) });') - } else { - g.writeln('${mr_var_name}.arg${i} });') - } + g.writeln('${mr_var_name}.arg${i} });') } } else { - if is_opt { - mr_base_styp := g.base_type(return_type) - if is_auto_heap { - g.writeln(' = HEAP${noscan}(${mr_base_styp}, ${mr_var_name}.arg${i});') - } else { - g.writeln(' = ${mr_var_name}.arg${i};') - } + if is_auto_heap { + g.writeln(' = HEAP${noscan}(${styp}, ${mr_var_name}.arg${i});') } else { - if is_auto_heap { - g.writeln(' = HEAP${noscan}(${styp}, ${mr_var_name}.arg${i});') - } else { - g.writeln(' = ${mr_var_name}.arg${i};') - } + g.writeln(' = ${mr_var_name}.arg${i};') } } } diff --git a/vlib/v/tests/multiret_with_result_test.v b/vlib/v/tests/multiret_with_result_test.v new file mode 100644 index 0000000000..4bfdb8b4f4 --- /dev/null +++ b/vlib/v/tests/multiret_with_result_test.v @@ -0,0 +1,15 @@ +[heap] +struct Foo { + a string + b int +} + +fn ret() !(int, Foo) { + return 0, Foo{} +} + +fn test_multiret_with_result() { + _, foo := ret()! + println(foo) + assert true +}