| 1 | struct Base { |
| 2 | i int |
| 3 | } |
| 4 | |
| 5 | struct Base1 { |
| 6 | Base |
| 7 | } |
| 8 | |
| 9 | struct Base2 { |
| 10 | Base |
| 11 | } |
| 12 | |
| 13 | struct Struct1 { |
| 14 | Base1 |
| 15 | } |
| 16 | |
| 17 | struct Struct1O { |
| 18 | Struct1 |
| 19 | } |
| 20 | |
| 21 | struct Struct2 { |
| 22 | Base2 |
| 23 | } |
| 24 | |
| 25 | struct Struct2O { |
| 26 | Struct2 |
| 27 | } |
| 28 | |
| 29 | fn (b &Base) func[T]() T { |
| 30 | t := T{ |
| 31 | i: b.i |
| 32 | } |
| 33 | if t.i == 0 { |
| 34 | } |
| 35 | return t |
| 36 | } |
| 37 | |
| 38 | fn test_generic_fn_with_embedded_structs() { |
| 39 | s1 := Struct1{} |
| 40 | s2 := Struct2{} |
| 41 | res1 := s1.func[Struct1O]() |
| 42 | res2 := s2.func[Struct2O]() |
| 43 | |
| 44 | assert res1.i == 0 |
| 45 | assert res2.i == 0 |
| 46 | } |
| 47 |