1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix function return anon_fn without parentheses

This commit is contained in:
yuyi 2020-06-22 22:03:31 +08:00 committed by GitHub
parent 504fd01f57
commit 73296e486a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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()
}

View File

@ -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
}