diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 1132d5334f..bfffc4251f 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2272,6 +2272,11 @@ fn (p &Parser) is_generic_call() bool { if nested_sbr_count > 0 { nested_sbr_count-- } else { + prev_tok := p.peek_token(i - 1) + // `funcs[i]()` is not generic call + if !(p.is_typename(prev_tok) || prev_tok.kind == .rsbr) { + return false + } if p.peek_token(i + 1).kind == .lpar { return true } diff --git a/vlib/v/tests/array_of_functions_direct_call_test.v b/vlib/v/tests/array_of_functions_direct_call_test.v new file mode 100644 index 0000000000..b601a2d68f --- /dev/null +++ b/vlib/v/tests/array_of_functions_direct_call_test.v @@ -0,0 +1,20 @@ +fn foo() string { + println('foo') + return 'foo' +} + +fn bar() string { + println('bar') + return 'bar' +} + +fn call() { + funcs := [foo, bar] + i := 1 + ret := funcs[i]() + assert ret == 'bar' +} + +fn test_array_of_functions_direct_call() { + call() +}