golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/apidiff/testdata/generics.go (about) 1 package p 2 3 //// Generics 4 5 // old 6 type G[T any] []T 7 8 // new 9 // OK: param name change 10 type G[A any] []A 11 12 // old 13 type GM[A, B comparable] map[A]B 14 15 // new 16 // i GM: changed from map[A]B to map[B]A 17 type GM[A, B comparable] map[B]A 18 19 // old 20 type GT[V any] struct { 21 } 22 23 func (GT[V]) M(*GT[V]) {} 24 25 // new 26 // OK 27 type GT[V any] struct { 28 } 29 30 func (GT[V]) M(*GT[V]) {} 31 32 // old 33 type GT2[V any] struct { 34 } 35 36 func (GT2[V]) M(*GT2[V]) {} 37 38 // new 39 // i GT2: changed from GT2[V any] to GT2[V comparable] 40 type GT2[V comparable] struct { 41 } 42 43 func (GT2[V]) M(*GT2[V]) {} 44 45 // both 46 type custom interface { 47 int 48 } 49 50 type GT3[E custom] map[E]int 51 52 // Instantiated types: 53 // Two instantiations of generic types 54 // with different type parameters are different. 55 56 // both 57 type H[T any] []T 58 59 // old 60 var V1 H[int] 61 62 type T int 63 64 var V2 H[T] 65 66 // new 67 // i V1: changed from H[int] to H[bool] 68 var V1 H[bool] 69 70 // i T: changed from int to bool 71 type T bool 72 73 // OK: we reported on T, so we don't need to here. 74 var V2 H[T] 75 76 // old 77 type t int 78 79 // new 80 // i t: changed from int to byte 81 type t byte 82 83 // both 84 var V3 H[t]