gen: fix generated `defer` (#5717)
parent
317b2dc579
commit
b0ce66d141
|
@ -850,15 +850,18 @@ fn (mut g Gen) stmt(node ast.Stmt) {
|
||||||
|
|
||||||
fn (mut g Gen) write_defer_stmts() {
|
fn (mut g Gen) write_defer_stmts() {
|
||||||
for defer_stmt in g.defer_stmts {
|
for defer_stmt in g.defer_stmts {
|
||||||
g.writeln('// defer')
|
g.writeln('// Defer begin')
|
||||||
if defer_stmt.ifdef.len > 0 {
|
if defer_stmt.ifdef.len > 0 {
|
||||||
g.writeln(defer_stmt.ifdef)
|
g.writeln(defer_stmt.ifdef)
|
||||||
g.stmts(defer_stmt.stmts)
|
g.stmts(defer_stmt.stmts)
|
||||||
g.writeln('')
|
g.writeln('')
|
||||||
g.writeln('#endif')
|
g.writeln('#endif')
|
||||||
} else {
|
} else {
|
||||||
|
g.indent--
|
||||||
g.stmts(defer_stmt.stmts)
|
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.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 {
|
if g.autofree {
|
||||||
// TODO: remove this, when g.write_autofree_stmts_when_needed works properly
|
// TODO: remove this, when g.write_autofree_stmts_when_needed works properly
|
||||||
|
|
Loading…
Reference in New Issue