autofree: fix and test var declarations

pull/6585/head
Alexander Medvednikov 2020-10-08 17:10:20 +02:00
parent 1123b8259a
commit 7d65e4cb10
2 changed files with 12 additions and 0 deletions

View File

@ -1388,6 +1388,12 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
// return
}
}
// Autofree tmp arg vars
first_right := assign_stmt.right[0]
af := g.pref.autofree && first_right is ast.CallExpr && !g.is_builtin_mod
if af {
g.autofree_call_pregen(first_right as ast.CallExpr)
}
//
// json_test failed w/o this check
if return_type != table.void_type && return_type != 0 {

View File

@ -46,6 +46,11 @@ fn str_tmp_expr_advanced() {
handle_strings('c' + 'd', add_strings('e' + 'f', 'g')) // both lvl 1 and lvl2 exprs must be freed
}
fn str_tmp_expr_advanced_var_decl() {
a := handle_strings('c' + 'd', add_strings('e' + 'f', 'g')) // both lvl 1 and lvl2 exprs must be freed
println(a)
}
struct Foo {
a int
b string
@ -114,6 +119,7 @@ fn main() {
foo()
str_tmp_expr()
str_tmp_expr_advanced()
str_tmp_expr_advanced_var_decl()
str_inter()
match_expr()
reassign_str()