parser: fix anon_fn with array arguments (#9414)

pull/9415/head
yuyi 2021-03-22 10:22:29 +08:00 committed by GitHub
parent c5bc349edb
commit cf6faaf215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -643,7 +643,7 @@ fn (mut p Parser) fn_args() ([]table.Param, bool, bool) {
} else { } else {
p.tok.lit p.tok.lit
} }
types_only := p.tok.kind in [.amp, .ellipsis, .key_fn] types_only := p.tok.kind in [.amp, .ellipsis, .key_fn, .lsbr]
|| (p.peek_tok.kind == .comma && p.table.known_type(argname)) || (p.peek_tok.kind == .comma && p.table.known_type(argname))
|| p.peek_tok.kind == .dot || p.peek_tok.kind == .rpar || p.peek_tok.kind == .dot || p.peek_tok.kind == .rpar
// TODO copy pasta, merge 2 branches // TODO copy pasta, merge 2 branches

View File

@ -0,0 +1,12 @@
fn fn_arg(f fn ([]int) int) int {
return f([1, 2, 3])
}
fn test_anon_fn_with_array_arguments() {
anon := fn (i []int) int {
return 0
}
println(fn_arg(anon))
assert fn_arg(anon) == 0
}