From 3f9b05a8761a30e7bf74949f87bdc300e2e50329 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 5 Nov 2020 18:59:36 +0200 Subject: [PATCH] vfmt: skip {} for pure fn declarations (let the bodies hit the floor) --- vlib/v/fmt/fmt.v | 8 +++++--- vlib/v/fmt/tests/fn_headers_with_no_bodies_keep.vv | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 vlib/v/fmt/tests/fn_headers_with_no_bodies_keep.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 5463b543e9..afdea27cf4 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1219,9 +1219,11 @@ pub fn (mut f Fmt) fn_decl(node ast.FnDecl) { f.attrs(node.attrs) f.write(node.stringify(f.table, f.cur_mod)) // `Expr` instead of `ast.Expr` in mod ast if node.language == .v { - f.writeln(' {') - f.stmts(node.stmts) - f.write('}') + if !node.no_body { + f.writeln(' {') + f.stmts(node.stmts) + f.write('}') + } if !node.is_anon { f.writeln('\n') } diff --git a/vlib/v/fmt/tests/fn_headers_with_no_bodies_keep.vv b/vlib/v/fmt/tests/fn_headers_with_no_bodies_keep.vv new file mode 100644 index 0000000000..c92fdba36d --- /dev/null +++ b/vlib/v/fmt/tests/fn_headers_with_no_bodies_keep.vv @@ -0,0 +1,5 @@ +fn proc_pidpath(int, voidptr, int) int + +fn C.realpath(charptr, charptr) &char + +fn C.chmod(byteptr, int) int