From cf6faaf215dd6d080ec90a5d22ff67b30454eefb Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 22 Mar 2021 10:22:29 +0800 Subject: [PATCH] parser: fix anon_fn with array arguments (#9414) --- vlib/v/parser/fn.v | 2 +- vlib/v/tests/anon_fn_with_array_arguments.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/anon_fn_with_array_arguments.v diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 3d7bfd2e79..0e8e68626d 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -643,7 +643,7 @@ fn (mut p Parser) fn_args() ([]table.Param, bool, bool) { } else { 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 == .dot || p.peek_tok.kind == .rpar // TODO copy pasta, merge 2 branches diff --git a/vlib/v/tests/anon_fn_with_array_arguments.v b/vlib/v/tests/anon_fn_with_array_arguments.v new file mode 100644 index 0000000000..3c2f3ae0d8 --- /dev/null +++ b/vlib/v/tests/anon_fn_with_array_arguments.v @@ -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 +}