mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix error for array of anon fn call (#13858)
This commit is contained in:
parent
04cc037955
commit
c71770d9c5
@ -531,6 +531,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||||||
info := sym.info as ast.Array
|
info := sym.info as ast.Array
|
||||||
elem_typ := c.table.sym(info.elem_type)
|
elem_typ := c.table.sym(info.elem_type)
|
||||||
if elem_typ.info is ast.FnType {
|
if elem_typ.info is ast.FnType {
|
||||||
|
node.return_type = elem_typ.info.func.return_type
|
||||||
return elem_typ.info.func.return_type
|
return elem_typ.info.func.return_type
|
||||||
} else {
|
} else {
|
||||||
c.error('cannot call the element of the array, it is not a function',
|
c.error('cannot call the element of the array, it is not a function',
|
||||||
@ -540,6 +541,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||||||
info := sym.info as ast.Map
|
info := sym.info as ast.Map
|
||||||
value_typ := c.table.sym(info.value_type)
|
value_typ := c.table.sym(info.value_type)
|
||||||
if value_typ.info is ast.FnType {
|
if value_typ.info is ast.FnType {
|
||||||
|
node.return_type = value_typ.info.func.return_type
|
||||||
return value_typ.info.func.return_type
|
return value_typ.info.func.return_type
|
||||||
} else {
|
} else {
|
||||||
c.error('cannot call the value of the map, it is not a function', node.pos)
|
c.error('cannot call the value of the map, it is not a function', node.pos)
|
||||||
@ -548,13 +550,12 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
|||||||
info := sym.info as ast.ArrayFixed
|
info := sym.info as ast.ArrayFixed
|
||||||
elem_typ := c.table.sym(info.elem_type)
|
elem_typ := c.table.sym(info.elem_type)
|
||||||
if elem_typ.info is ast.FnType {
|
if elem_typ.info is ast.FnType {
|
||||||
|
node.return_type = elem_typ.info.func.return_type
|
||||||
return elem_typ.info.func.return_type
|
return elem_typ.info.func.return_type
|
||||||
} else {
|
} else {
|
||||||
c.error('cannot call the element of the array, it is not a function',
|
c.error('cannot call the element of the array, it is not a function',
|
||||||
node.pos)
|
node.pos)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// TODO: assert? is this possible?
|
|
||||||
}
|
}
|
||||||
found = true
|
found = true
|
||||||
return ast.string_type
|
return ast.string_type
|
||||||
|
8
vlib/v/tests/array_of_anon_fn_call_test.v
Normal file
8
vlib/v/tests/array_of_anon_fn_call_test.v
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fn test_array_of_anon_fn_call() {
|
||||||
|
xs := [fn (s string) (string, u32) {
|
||||||
|
return s, 0
|
||||||
|
}]
|
||||||
|
r, n := xs[0]('e')
|
||||||
|
assert n == 0
|
||||||
|
assert r == 'e'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user