mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
9662b79662
commit
a28249c119
@ -1266,10 +1266,16 @@ pub fn (t &TypeSymbol) find_method_with_generic_parent(name string) ?Fn {
|
||||
Struct, Interface, SumType {
|
||||
mut method := x
|
||||
generic_names := parent_sym.info.generic_types.map(table.sym(it).name)
|
||||
if rt := table.resolve_generic_to_concrete(method.return_type,
|
||||
generic_names, t.info.concrete_types)
|
||||
{
|
||||
method.return_type = rt
|
||||
return_sym := table.sym(method.return_type)
|
||||
if return_sym.kind == .struct_ {
|
||||
method.return_type = table.unwrap_generic_type(method.return_type,
|
||||
generic_names, t.info.concrete_types)
|
||||
} else {
|
||||
if rt := table.resolve_generic_to_concrete(method.return_type,
|
||||
generic_names, t.info.concrete_types)
|
||||
{
|
||||
method.return_type = rt
|
||||
}
|
||||
}
|
||||
method.params = method.params.clone()
|
||||
for mut param in method.params {
|
||||
|
35
vlib/v/tests/for_in_iterator_of_generic_struct_2_test.v
Normal file
35
vlib/v/tests/for_in_iterator_of_generic_struct_2_test.v
Normal file
@ -0,0 +1,35 @@
|
||||
pub struct Item<V> {
|
||||
pub:
|
||||
value V
|
||||
}
|
||||
|
||||
pub struct Iter<V> {
|
||||
arr []V
|
||||
mut:
|
||||
ix int
|
||||
}
|
||||
|
||||
pub fn (mut iter Iter<V>) next() ?Item<V> {
|
||||
if iter.ix >= iter.arr.len {
|
||||
return none
|
||||
}
|
||||
|
||||
val := iter.arr[iter.ix]
|
||||
iter.ix += 1
|
||||
return Item<V>{val}
|
||||
}
|
||||
|
||||
fn iterator<V>(arr []V) Iter<V> {
|
||||
return Iter<V>{arr, 0}
|
||||
}
|
||||
|
||||
fn test_for_in_iterator_of_generic_struct() {
|
||||
mut ret := []int{}
|
||||
mut x := iterator<int>([1, 2, 3, 4, 5])
|
||||
for item in x {
|
||||
println(item.value)
|
||||
ret << item.value
|
||||
}
|
||||
println(ret)
|
||||
assert ret == [1, 2, 3, 4, 5]
|
||||
}
|
Loading…
Reference in New Issue
Block a user