From 73296e486a5c4b6f6d5163bf45c168606fa60e41 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 22 Jun 2020 22:03:31 +0800 Subject: [PATCH] parser: fix function return anon_fn without parentheses --- vlib/v/parser/fn.v | 2 +- vlib/v/tests/fn_test.v | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 9cea66a17e..cc63a9df46 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -219,7 +219,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { mut end_pos := p.prev_tok.position() // Return type mut return_type := table.void_type - if p.tok.kind.is_start_of_type() { + if p.tok.kind.is_start_of_type() || (p.tok.kind == .key_fn && p.tok.line_nr == p.prev_tok.line_nr) { end_pos = p.tok.position() return_type = p.parse_type() } diff --git a/vlib/v/tests/fn_test.v b/vlib/v/tests/fn_test.v index e67331967b..deda0191b2 100644 --- a/vlib/v/tests/fn_test.v +++ b/vlib/v/tests/fn_test.v @@ -144,3 +144,14 @@ fn test_fn_type_call() { } assert st1.f(10) == 1010 } + +fn ff() fn () int { + return fn () int { + return 22 + } +} + +fn test_fn_return_fn() { + f := ff() + assert f() == 22 +}