v2 / vlib / v / tests / generics / generic_struct_test.v
44 lines · 39 sloc · 541 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test {}
2
3fn (t Test) test[T](val T) {
4 $for f in T.fields {
5 value := val.$(f.name)
6 $if f.is_option {
7 $if f.typ is $struct {
8 _ := 1
9 t.test(value)
10 } $else $if f.typ is string {
11 _ := 2
12 } $else $if f.typ is ?string {
13 _ := 3
14 } $else {
15 _ := 4
16 }
17 } $else {
18 $if f.typ is $struct {
19 t.test(value)
20 } $else $if f.typ is string {
21 _ := 5
22 }
23 }
24 }
25}
26
27struct Bb {
28 a ?string
29}
30
31struct Cc {
32 b Bb
33}
34
35struct Aa[T] {
36 a T
37}
38
39fn test_main() {
40 a := Aa[Cc]{}
41 t := Test{}
42 t.test(a)
43 assert true
44}
45