mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
autofree: do not free _ vars
This commit is contained in:
parent
e0d20eadff
commit
53bed596e7
@ -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]`)
|
// 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 &&
|
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 {
|
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.write('string_free(&')
|
||||||
g.expr(assign_stmt.left[0])
|
g.expr(assign_stmt.left[0])
|
||||||
g.writeln('); // free str on re-assignment')
|
g.writeln('); // free str on re-assignment')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// json_test failed w/o this check
|
// json_test failed w/o this check
|
||||||
if return_type != table.void_type && return_type != 0 {
|
if return_type != table.void_type && return_type != 0 {
|
||||||
sym := g.table.get_type_symbol(return_type)
|
sym := g.table.get_type_symbol(return_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user