autofree: do not free _ vars

pull/6345/head
Alexander Medvednikov 2020-09-11 13:58:12 +02:00
parent e0d20eadff
commit 53bed596e7
1 changed files with 6 additions and 3 deletions

View File

@ -1328,10 +1328,13 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
// Free the old value assigned to this string var (only if it's `str = [new value]`)
if g.pref.autofree && assign_stmt.op == .assign && assign_stmt.left_types.len == 1 &&
assign_stmt.left_types[0] == table.string_type && assign_stmt.left[0] is ast.Ident {
ident := assign_stmt.left[0] as ast.Ident
if ident.name != '_' {
g.write('string_free(&')
g.expr(assign_stmt.left[0])
g.writeln('); // free str on re-assignment')
}
}
// json_test failed w/o this check
if return_type != table.void_type && return_type != 0 {
sym := g.table.get_type_symbol(return_type)