1
0
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:
yuyi 2020-07-08 13:39:11 +08:00 committed by GitHub
parent 317b2dc579
commit b0ce66d141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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')
}
}

View File

@ -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