parent
1679e07619
commit
9326cb9d67
|
@ -559,12 +559,12 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
||||||
}
|
}
|
||||||
if !found && mut node.left is ast.IndexExpr {
|
if !found && mut node.left is ast.IndexExpr {
|
||||||
c.expr(node.left)
|
c.expr(node.left)
|
||||||
sym := c.table.sym(node.left.left_type)
|
sym := c.table.final_sym(node.left.left_type)
|
||||||
if sym.info is ast.Array {
|
if sym.info is ast.Array {
|
||||||
elem_sym := c.table.sym(sym.info.elem_type)
|
elem_sym := c.table.sym(sym.info.elem_type)
|
||||||
if elem_sym.info is ast.FnType {
|
if elem_sym.info is ast.FnType {
|
||||||
node.return_type = elem_sym.info.func.return_type
|
func = elem_sym.info.func
|
||||||
return elem_sym.info.func.return_type
|
found = true
|
||||||
} 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)
|
||||||
|
@ -572,23 +572,21 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
||||||
} else if sym.info is ast.Map {
|
} else if sym.info is ast.Map {
|
||||||
value_sym := c.table.sym(sym.info.value_type)
|
value_sym := c.table.sym(sym.info.value_type)
|
||||||
if value_sym.info is ast.FnType {
|
if value_sym.info is ast.FnType {
|
||||||
node.return_type = value_sym.info.func.return_type
|
func = value_sym.info.func
|
||||||
return value_sym.info.func.return_type
|
found = true
|
||||||
} 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)
|
||||||
}
|
}
|
||||||
} else if sym.info is ast.ArrayFixed {
|
} else if sym.info is ast.ArrayFixed {
|
||||||
elem_sym := c.table.sym(sym.info.elem_type)
|
elem_sym := c.table.sym(sym.info.elem_type)
|
||||||
if elem_sym.info is ast.FnType {
|
if elem_sym.info is ast.FnType {
|
||||||
node.return_type = elem_sym.info.func.return_type
|
func = elem_sym.info.func
|
||||||
return elem_sym.info.func.return_type
|
found = true
|
||||||
} 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
found = true
|
|
||||||
return ast.string_type
|
|
||||||
}
|
}
|
||||||
if !found && mut node.left is ast.CallExpr {
|
if !found && mut node.left is ast.CallExpr {
|
||||||
c.expr(node.left)
|
c.expr(node.left)
|
||||||
|
|
|
@ -1,7 +1,20 @@
|
||||||
vlib/v/checker/tests/fn_type_mismatch.vv:11:15: error: invalid array element: expected `fn (int, int) f32`, not `fn (f32, f32) f32`
|
vlib/v/checker/tests/fn_type_mismatch.vv:11:15: error: invalid array element: expected `fn (int, int) f32`, not `fn (f32, f32) f32`
|
||||||
9 |
|
9 |
|
||||||
10 | fn main() {
|
10 | fn main() {
|
||||||
11 | fns := [add, div]
|
11 | fns := [add, div]
|
||||||
| ~~~
|
| ~~~
|
||||||
12 | println(fns[0](10.0, 5.0))
|
12 | println(fns[0](10.0, 5.0))
|
||||||
13 | println(fns[1](10.0, 5.0))
|
13 | println(fns[1](10.0, 5.0))
|
||||||
|
vlib/v/checker/tests/fn_type_mismatch.vv:12:17: error: cannot use `float literal` as `int` in argument 1 to ``
|
||||||
|
10 | fn main() {
|
||||||
|
11 | fns := [add, div]
|
||||||
|
12 | println(fns[0](10.0, 5.0))
|
||||||
|
| ~~~~
|
||||||
|
13 | println(fns[1](10.0, 5.0))
|
||||||
|
14 | }
|
||||||
|
vlib/v/checker/tests/fn_type_mismatch.vv:13:17: error: cannot use `float literal` as `int` in argument 1 to ``
|
||||||
|
11 | fns := [add, div]
|
||||||
|
12 | println(fns[0](10.0, 5.0))
|
||||||
|
13 | println(fns[1](10.0, 5.0))
|
||||||
|
| ~~~~
|
||||||
|
14 | }
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
struct Bar {}
|
||||||
|
|
||||||
|
fn test_map_get_anon_fn_value_with_mut_arg() {
|
||||||
|
foo := {
|
||||||
|
0: fn (mut bar Bar) int {
|
||||||
|
return 22
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mut bar := Bar{}
|
||||||
|
ret := foo[0](mut bar)
|
||||||
|
|
||||||
|
println(ret)
|
||||||
|
assert ret == 22
|
||||||
|
}
|
Loading…
Reference in New Issue