diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 6d207d7f0d..d9d4c0eaf8 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2494,8 +2494,7 @@ fn (mut g Gen) return_statement(node ast.Return) { if fn_return_is_optional { tmp := g.new_tmp_var() styp := g.typ(g.fn_decl.return_type) - g.writeln('$styp $tmp;') - g.writeln('${tmp}.ok = true;') + g.writeln('$styp $tmp = {.ok = true};') g.writeln('return $tmp;') } else { g.writeln('return;') @@ -2508,7 +2507,7 @@ fn (mut g Gen) return_statement(node ast.Return) { mut is_regular_option := g.typ(node.types[0]) == 'Option' if optional_none || is_regular_option { tmp := g.new_tmp_var() - g.write('/*opt promotion*/ Option $tmp = ') + g.write('Option $tmp = ') g.expr_with_cast(node.exprs[0], node.types[0], g.fn_decl.return_type) g.writeln(';') styp := g.typ(g.fn_decl.return_type) @@ -2527,7 +2526,7 @@ fn (mut g Gen) return_statement(node ast.Return) { opt_type = g.typ(g.fn_decl.return_type) // Create a tmp for this option opt_tmp = g.new_tmp_var() - g.write('$opt_type $opt_tmp;') + g.writeln('$opt_type $opt_tmp;') styp = g.base_type(g.fn_decl.return_type) g.write('opt_ok2(&($styp/*X*/[]) { ') } else { @@ -2596,8 +2595,8 @@ fn (mut g Gen) return_statement(node ast.Return) { opt_type := g.typ(g.fn_decl.return_type) // Create a tmp for this option opt_tmp := g.new_tmp_var() - g.write('$opt_type $opt_tmp;') - g.write('/*:)$return_sym.name*/opt_ok2(&($styp[]) { ') + g.writeln('$opt_type $opt_tmp;') + g.write('opt_ok2(&($styp[]) { ') if !g.fn_decl.return_type.is_ptr() && node.types[0].is_ptr() { // Automatic Dereference for optional g.write('*') diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index 99206f99cd..0adee441e4 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -249,7 +249,8 @@ fn (mut g Gen) call_expr(node ast.CallExpr) { g.inside_call = false } gen_or := node.or_block.kind != .absent - cur_line := if gen_or && g.is_assign_rhs { + is_gen_or_and_assign_rhs := gen_or && g.is_assign_rhs + cur_line := if is_gen_or_and_assign_rhs { line := g.go_before_stmt(0) g.out.write(tabs[g.indent]) line @@ -268,7 +269,9 @@ fn (mut g Gen) call_expr(node ast.CallExpr) { } if gen_or { g.or_block(tmp_opt, node.or_block, node.return_type) - g.write('\n\t$cur_line$tmp_opt') + if is_gen_or_and_assign_rhs { + g.write('\n$cur_line$tmp_opt') + } } }