mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: fix for in
iterator with generic structs (#18344)
This commit is contained in:
parent
02ea6028af
commit
325f64bc60
@ -1905,7 +1905,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
|
|||||||
mut info := ts.info
|
mut info := ts.info
|
||||||
info.is_generic = false
|
info.is_generic = false
|
||||||
info.concrete_types = final_concrete_types
|
info.concrete_types = final_concrete_types
|
||||||
info.parent_type = typ
|
info.parent_type = typ.set_flag(.generic)
|
||||||
info.fields = fields
|
info.fields = fields
|
||||||
new_idx := t.register_sym(
|
new_idx := t.register_sym(
|
||||||
kind: .struct_
|
kind: .struct_
|
||||||
@ -1940,7 +1940,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
|
|||||||
mut info := ts.info
|
mut info := ts.info
|
||||||
info.is_generic = false
|
info.is_generic = false
|
||||||
info.concrete_types = final_concrete_types
|
info.concrete_types = final_concrete_types
|
||||||
info.parent_type = typ
|
info.parent_type = typ.set_flag(.generic)
|
||||||
info.fields = fields
|
info.fields = fields
|
||||||
info.variants = variants
|
info.variants = variants
|
||||||
new_idx := t.register_sym(
|
new_idx := t.register_sym(
|
||||||
@ -1984,7 +1984,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
|
|||||||
mut info := ts.info
|
mut info := ts.info
|
||||||
info.is_generic = false
|
info.is_generic = false
|
||||||
info.concrete_types = final_concrete_types
|
info.concrete_types = final_concrete_types
|
||||||
info.parent_type = typ
|
info.parent_type = typ.set_flag(.generic)
|
||||||
info.fields = fields
|
info.fields = fields
|
||||||
info.methods = imethods
|
info.methods = imethods
|
||||||
new_idx := t.register_sym(
|
new_idx := t.register_sym(
|
||||||
|
28
vlib/v/tests/for_in_iterator_of_generic_struct_3_test.v
Normal file
28
vlib/v/tests/for_in_iterator_of_generic_struct_3_test.v
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
struct MyGenericArray[T] {
|
||||||
|
arr []T
|
||||||
|
mut:
|
||||||
|
idx int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (mut self MyGenericArray[T]) next() ?T {
|
||||||
|
if self.arr.len <= self.idx {
|
||||||
|
return none
|
||||||
|
} else {
|
||||||
|
defer {
|
||||||
|
self.idx++
|
||||||
|
}
|
||||||
|
return self.arr[self.idx]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_for_in_iterator_of_generic_struct() {
|
||||||
|
mut a := MyGenericArray{[4, 5, 6], 1}
|
||||||
|
mut ret := []int{}
|
||||||
|
for i in a {
|
||||||
|
println(i)
|
||||||
|
ret << i
|
||||||
|
}
|
||||||
|
assert ret.len == 2
|
||||||
|
assert ret[0] == 5
|
||||||
|
assert ret[1] == 6
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user