diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index d531f28de4..b43af05890 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1037,12 +1037,12 @@ fn (mut g Gen) stmt(node ast.Stmt) { } ast.Return { g.write_defer_stmts_when_needed() - af := g.pref.autofree && node.exprs.len > 0 && node.exprs[0] is ast.CallExpr && !g.is_builtin_mod - if g.pref.autofree { + // af := g.pref.autofree && node.exprs.len > 0 && node.exprs[0] is ast.CallExpr && !g.is_builtin_mod + af := g.pref.autofree && !g.is_builtin_mod + if af { g.writeln('// ast.Return free') // g.autofree_scope_vars(node.pos.pos - 1, node.pos.line_nr, true) g.writeln('// ast.Return free_end') - // g.write_autofree_stmts_when_needed(node) } g.return_statement(node) } diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index b5debbfda5..c4dd694c9c 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -181,17 +181,6 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl, skip bool) { } } -/* -fn (mut g Gen) write_autofree_stmts_when_needed(r ast.Return) { - // TODO: write_autofree_stmts_when_needed should account for the current local scope vars. - // TODO: write_autofree_stmts_when_needed should not free the returned variables. - // It may require rewriting g.return_statement to assign the expressions - // to temporary variables, then protecting *them* from autofreeing ... - // g.writeln('// autofreeings before return: -------') - // g.writeln(g.autofree_scope_vars(g.fn_decl.body_pos.pos)) - // g.writeln('//--------------------------------------------------- ') // //g.write( g.autofree_scope_vars(r.pos.pos) ) -} -*/ fn (mut g Gen) write_defer_stmts_when_needed() { if g.defer_stmts.len > 0 { g.write_defer_stmts()