parent
9662b79662
commit
a28249c119
|
@ -1266,11 +1266,17 @@ 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)
|
||||
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 {
|
||||
if pt := table.resolve_generic_to_concrete(param.typ,
|
||||
|
|
|
@ -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