fmt: process `defer` statement

pull/3855/head
Alexey 2020-02-26 22:44:42 +03:00 committed by GitHub
parent 9d61f4fad1
commit b1ea908b3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -138,6 +138,11 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
f.indent--
f.writeln(')\n')
}
ast.DeferStmt {
f.writeln('defer {')
f.stmts(it.stmts)
f.writeln('}')
}
ast.ExprStmt {
f.expr(it.expr)
if !f.single_line_if {

View File

@ -83,6 +83,12 @@ fn get_user_ptr() &User {
return &User{}
}
fn fn_with_defer() {
defer {
close()
}
}
struct Foo {
field1 int
field2 string

View File

@ -88,6 +88,11 @@ fn get_user_ptr() & User {
return &User{}
}
fn fn_with_defer() {
defer { close()
}
}
struct Foo {
field1 int
field2 string