diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 0c4fc12c4a..1d3dcbb061 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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 { diff --git a/vlib/v/fmt/tests/simple_expected.vv b/vlib/v/fmt/tests/simple_expected.vv index 3ce076e335..f01413ddc2 100644 --- a/vlib/v/fmt/tests/simple_expected.vv +++ b/vlib/v/fmt/tests/simple_expected.vv @@ -83,6 +83,12 @@ fn get_user_ptr() &User { return &User{} } +fn fn_with_defer() { + defer { + close() + } +} + struct Foo { field1 int field2 string diff --git a/vlib/v/fmt/tests/simple_input.vv b/vlib/v/fmt/tests/simple_input.vv index f5b1ceebc3..91fe2269d7 100644 --- a/vlib/v/fmt/tests/simple_input.vv +++ b/vlib/v/fmt/tests/simple_input.vv @@ -88,6 +88,11 @@ fn get_user_ptr() & User { return &User{} } +fn fn_with_defer() { +defer { close() +} +} + struct Foo { field1 int field2 string