mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gen: fix generated defer
(#5717)
This commit is contained in:
parent
317b2dc579
commit
b0ce66d141
@ -850,15 +850,18 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||
|
||||
fn (mut g Gen) write_defer_stmts() {
|
||||
for defer_stmt in g.defer_stmts {
|
||||
g.writeln('// defer')
|
||||
g.writeln('// Defer begin')
|
||||
if defer_stmt.ifdef.len > 0 {
|
||||
g.writeln(defer_stmt.ifdef)
|
||||
g.stmts(defer_stmt.stmts)
|
||||
g.writeln('')
|
||||
g.writeln('#endif')
|
||||
} else {
|
||||
g.indent--
|
||||
g.stmts(defer_stmt.stmts)
|
||||
g.indent++
|
||||
}
|
||||
g.writeln('// Defer end')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,9 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
||||
}
|
||||
g.stmts(it.stmts)
|
||||
// ////////////
|
||||
g.write_defer_stmts_when_needed()
|
||||
if it.return_type == table.void_type {
|
||||
g.write_defer_stmts_when_needed()
|
||||
}
|
||||
// /////////
|
||||
if g.autofree {
|
||||
// TODO: remove this, when g.write_autofree_stmts_when_needed works properly
|
||||
|
Loading…
Reference in New Issue
Block a user