mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: autofree scope var position fixes
This commit is contained in:
parent
6245876806
commit
612fe1b8fb
@ -622,11 +622,16 @@ fn (mut g Gen) stmts(stmts []ast.Stmt) {
|
||||
g.write('')
|
||||
g.write(')')
|
||||
}
|
||||
if g.pref.autofree && g.pref.experimental && stmts.len > 0 {
|
||||
stmt := stmts[stmts.len - 1]
|
||||
if g.pref.autofree && g.pref.experimental && !g.inside_vweb_tmpl && stmts.len > 0 {
|
||||
// use the first stmt to get the scope
|
||||
stmt := stmts[0]
|
||||
// stmt := stmts[stmts.len-1]
|
||||
if stmt !is ast.FnDecl {
|
||||
// g.writeln('// autofree scope')
|
||||
g.autofree_scope_vars(stmt.position().pos)
|
||||
// g.writeln('// autofree_scope_vars($stmt.position().pos) | ${typeof(stmt)}')
|
||||
// go back 1 position is important so we dont get the
|
||||
// internal scope of for loops and possibly other nodes
|
||||
g.autofree_scope_vars(stmt.position().pos-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1586,9 +1591,9 @@ fn (g &Gen) autofree_var_call(free_fn_name string, v ast.Var) {
|
||||
return
|
||||
}
|
||||
if v.typ.is_ptr() {
|
||||
g.writeln('\t${free_fn_name}($v.name); // autofreed ptr var')
|
||||
g.writeln('\t${free_fn_name}(${c_name(v.name)}); // autofreed ptr var')
|
||||
} else {
|
||||
g.writeln('\t${free_fn_name}(&$v.name); // autofreed var')
|
||||
g.writeln('\t${free_fn_name}(&${c_name(v.name)}); // autofreed var')
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user