From b1ea908b3b2344962894b78d6788c5849e4412ac Mon Sep 17 00:00:00 2001
From: Alexey <alex.esprit@gmail.com>
Date: Wed, 26 Feb 2020 22:44:42 +0300
Subject: [PATCH] fmt: process `defer` statement

---
 vlib/v/fmt/fmt.v                    | 5 +++++
 vlib/v/fmt/tests/simple_expected.vv | 6 ++++++
 vlib/v/fmt/tests/simple_input.vv    | 5 +++++
 3 files changed, 16 insertions(+)

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