mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic array.map with generic callback fn (#11991)
This commit is contained in:
parent
2ee873d6ca
commit
d6a4bce2ef
@ -2683,7 +2683,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||
ast.FnType { arg_sym.info.func.return_type }
|
||||
else { arg_type }
|
||||
}
|
||||
node.return_type = c.table.find_or_register_array(ret_type)
|
||||
node.return_type = c.table.find_or_register_array(c.unwrap_generic(ret_type))
|
||||
} else if method_name == 'filter' {
|
||||
// check fn
|
||||
c.check_map_and_filter(false, elem_typ, node)
|
||||
|
21
vlib/v/tests/generics_array_map_with_generic_callback_test.v
Normal file
21
vlib/v/tests/generics_array_map_with_generic_callback_test.v
Normal file
@ -0,0 +1,21 @@
|
||||
fn test_generics_array_map_with_generic_callback() {
|
||||
mut a := []Sth{}
|
||||
a = arr_generic<Sth>(buggy_cb)
|
||||
println(a)
|
||||
assert a.len == 0
|
||||
}
|
||||
|
||||
fn arr_generic<T>(cb fn (int) T) []T {
|
||||
return []int{}.map(cb(it))
|
||||
}
|
||||
|
||||
fn buggy_cb(a int) Sth {
|
||||
return Sth{
|
||||
a: a
|
||||
}
|
||||
}
|
||||
|
||||
struct Sth {
|
||||
a int
|
||||
b string
|
||||
}
|
Loading…
Reference in New Issue
Block a user