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

parser: fix array of functions direct call (#16838)

This commit is contained in:
yuyi 2023-01-02 20:12:07 +08:00 committed by GitHub
parent 9d49b69b69
commit f71572a50f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

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

View File

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