v2 / vlib / v / tests / generics / generic_interface_nested_struct_infer_test.v
31 lines · 25 sloc · 502 bytes · fd3b3f4c53739e35cf115f1abc85e669f2cf8907
Raw
1// Regression test for #19618.
2// Generic interface inference should bind nested generic struct arguments.
3
4interface MyInterface[T] {
5 is_good(a T) bool
6}
7
8struct MyStruct[T] {}
9
10struct Opt[T] {
11 x ?T
12}
13
14fn (_ MyStruct[T]) is_good(a Opt[T]) bool {
15 if _ := a.x {
16 return true
17 }
18 return false
19}
20
21fn check[T](a MyInterface[T], b T) bool {
22 return a.is_good(b)
23}
24
25fn test_generic_interface_infers_nested_generic_struct_argument() {
26 a := MyStruct[int]{}
27 b := Opt[int]{
28 x: 6
29 }
30 assert check(a, b)
31}
32