From 1abdf2d68f1f0d1c0f4083b24c7310ffe726c70f Mon Sep 17 00:00:00 2001 From: krischerven <50562493+krischerven@users.noreply.github.com> Date: Sat, 11 Apr 2020 19:38:14 -0400 Subject: [PATCH] cgen: fix missing defer in fn main() --- vlib/v/gen/cgen.v | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 6aa3e526eb..704fa134bf 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -885,11 +885,13 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) { if g.is_test { verror('test files cannot have function `main`') } - g.writeln('\treturn 0;') } if g.defer_stmts.len > 0 { g.write_defer_stmts() } + if is_main { + g.writeln('\treturn 0;') + } g.writeln('}') g.defer_stmts = [] g.fn_decl = 0