autofree: fix unused var error

pull/7005/head
Alexander Medvednikov 2020-11-28 20:33:32 +01:00
parent 91007e87d2
commit 159abd4727
2 changed files with 3 additions and 14 deletions

View File

@ -1037,12 +1037,12 @@ fn (mut g Gen) stmt(node ast.Stmt) {
} }
ast.Return { ast.Return {
g.write_defer_stmts_when_needed() g.write_defer_stmts_when_needed()
af := g.pref.autofree && node.exprs.len > 0 && node.exprs[0] is ast.CallExpr && !g.is_builtin_mod // 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 && !g.is_builtin_mod
if af {
g.writeln('// ast.Return free') g.writeln('// ast.Return free')
// g.autofree_scope_vars(node.pos.pos - 1, node.pos.line_nr, true) // g.autofree_scope_vars(node.pos.pos - 1, node.pos.line_nr, true)
g.writeln('// ast.Return free_end') g.writeln('// ast.Return free_end')
// g.write_autofree_stmts_when_needed(node)
} }
g.return_statement(node) g.return_statement(node)
} }

View File

@ -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() { fn (mut g Gen) write_defer_stmts_when_needed() {
if g.defer_stmts.len > 0 { if g.defer_stmts.len > 0 {
g.write_defer_stmts() g.write_defer_stmts()