pull/12037/head
parent
ce0867f40c
commit
cb149bfa00
|
@ -2811,19 +2811,29 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr) ast.Type {
|
|||
elem_typ := c.table.get_type_symbol(info.elem_type)
|
||||
if elem_typ.info is ast.FnType {
|
||||
return elem_typ.info.func.return_type
|
||||
} else {
|
||||
c.error('cannot call the element of the array, it is not a function',
|
||||
node.pos)
|
||||
}
|
||||
} else if sym.kind == .map {
|
||||
info := sym.info as ast.Map
|
||||
value_typ := c.table.get_type_symbol(info.value_type)
|
||||
if value_typ.info is ast.FnType {
|
||||
return value_typ.info.func.return_type
|
||||
} else {
|
||||
c.error('cannot call the value of the map, it is not a function', node.pos)
|
||||
}
|
||||
} else if sym.kind == .array_fixed {
|
||||
info := sym.info as ast.ArrayFixed
|
||||
elem_typ := c.table.get_type_symbol(info.elem_type)
|
||||
if elem_typ.info is ast.FnType {
|
||||
return elem_typ.info.func.return_type
|
||||
} else {
|
||||
c.error('cannot call the element of the array, it is not a function',
|
||||
node.pos)
|
||||
}
|
||||
} else {
|
||||
// TODO: assert? is this possible?
|
||||
}
|
||||
found = true
|
||||
return ast.string_type
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
vlib/v/checker/tests/index_invalid_call.vv:4:20: error: cannot call the value of the map, it is not a function
|
||||
2 | fn main() {
|
||||
3 | m := map[string]string
|
||||
4 | eprintln(m['abc']())
|
||||
| ^
|
||||
5 | array := ["", "1"]
|
||||
6 | array[0]()
|
||||
vlib/v/checker/tests/index_invalid_call.vv:6:11: error: cannot call the element of the array, it is not a function
|
||||
4 | eprintln(m['abc']())
|
||||
5 | array := ["", "1"]
|
||||
6 | array[0]()
|
||||
| ^
|
||||
7 | }
|
|
@ -0,0 +1,7 @@
|
|||
// fixes https://github.com/vlang/v/issues/11539 , copied example map test code from https://github.com/spytheman
|
||||
fn main() {
|
||||
m := map[string]string
|
||||
eprintln(m['abc']())
|
||||
array := ["", "1"]
|
||||
array[0]()
|
||||
}
|
Loading…
Reference in New Issue