From c811b5343a1872192a53c51aa331159ed293fdf6 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 24 Sep 2022 04:46:15 +0800 Subject: [PATCH] cgen: minor cleanup in return_stmt() (#15854) --- vlib/v/gen/c/cgen.v | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 32b325b1af..d40d7f8236 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4324,32 +4324,26 @@ fn (mut g Gen) return_stmt(node ast.Return) { for i, expr in node.exprs { // Check if we are dealing with a multi return and handle it seperately if g.expr_is_multi_return_call(expr) { - c := expr as ast.CallExpr - expr_sym := g.table.sym(c.return_type) - // Create a tmp for this call + call_expr := expr as ast.CallExpr + expr_sym := g.table.sym(call_expr.return_type) mut tmp := g.new_tmp_var() - if !c.return_type.has_flag(.optional) { - s := g.go_before_stmt(0) - expr_styp := g.typ(c.return_type) + if !call_expr.return_type.has_flag(.optional) + && !call_expr.return_type.has_flag(.result) { + line := g.go_before_stmt(0) + expr_styp := g.typ(call_expr.return_type) g.write('$expr_styp $tmp=') g.expr(expr) g.writeln(';') multi_unpack += g.go_before_stmt(0) - g.write(s) + g.write(line) } else { - s := g.go_before_stmt(0) - // TODO - // I (emily) am sorry for doing this - // I cant find another way to do this so right now - // this will have to do. + line := g.go_before_stmt(0) g.tmp_count-- g.expr(expr) multi_unpack += g.go_before_stmt(0) - g.write(s) - // modify tmp so that it is the opt deref - // TODO copy-paste from cgen.v:2397 - expr_styp := g.base_type(c.return_type) - tmp = ('/*opt*/(*($expr_styp*)${tmp}.data)') + g.write(line) + expr_styp := g.base_type(call_expr.return_type) + tmp = ('(*($expr_styp*)${tmp}.data)') } expr_types := expr_sym.mr_info().types for j, _ in expr_types {