golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/rename/generics.txt (about) 1 This test exercises various renaming features on generic code. 2 3 Fixed bugs: 4 5 - golang/go#61614: renaming a method of a type in a package that uses type 6 parameter composite lits used to panic, because previous iterations of the 7 satisfy analysis did not account for this language feature. 8 9 - golang/go#61635: renaming type parameters did not work when they were 10 capitalized and the package was imported by another package. 11 12 -- go.mod -- 13 module example.com 14 go 1.20 15 16 -- a.go -- 17 package a 18 19 type I int 20 21 func (I) m() {} //@rename("m", "M", mToM) 22 23 func _[P ~[]int]() { 24 _ = P{} 25 } 26 27 -- @mToM/a.go -- 28 @@ -5 +5 @@ 29 -func (I) m() {} //@rename("m", "M", mToM) 30 +func (I) M() {} //@rename("m", "M", mToM) 31 -- g.go -- 32 package a 33 34 type S[P any] struct { //@rename("P", "Q", PToQ) 35 P P 36 F func(P) P 37 } 38 39 func F[R any](r R) { 40 var _ R //@rename("R", "S", RToS) 41 } 42 43 -- @PToQ/g.go -- 44 @@ -3,3 +3,3 @@ 45 -type S[P any] struct { //@rename("P", "Q", PToQ) 46 - P P 47 - F func(P) P 48 +type S[Q any] struct { //@rename("P", "Q", PToQ) 49 + P Q 50 + F func(Q) Q 51 -- @RToS/g.go -- 52 @@ -8,2 +8,2 @@ 53 -func F[R any](r R) { 54 - var _ R //@rename("R", "S", RToS) 55 +func F[S any](r S) { 56 + var _ S //@rename("R", "S", RToS) 57 -- issue61635/p.go -- 58 package issue61635 59 60 type builder[S ~[]F, F ~string] struct { //@rename("S", "T", SToT) 61 name string 62 elements S 63 elemData map[F][]ElemData[F] 64 // other fields... 65 } 66 67 type ElemData[F ~string] struct { 68 Name F 69 // other fields... 70 } 71 72 type BuilderImpl[S ~[]F, F ~string] struct{ builder[S, F] } 73 74 -- importer/i.go -- 75 package importer 76 77 import "example.com/issue61635" // importing is necessary to repro golang/go#61635 78 79 var _ issue61635.ElemData[string] 80 81 -- @SToT/issue61635/p.go -- 82 @@ -3 +3 @@ 83 -type builder[S ~[]F, F ~string] struct { //@rename("S", "T", SToT) 84 +type builder[T ~[]F, F ~string] struct { //@rename("S", "T", SToT) 85 @@ -5 +5 @@ 86 - elements S 87 + elements T 88 -- instances/type.go -- 89 package instances 90 91 type R[P any] struct { //@rename("R", "u", Rtou) 92 Next *R[P] //@rename("R", "s", RTos) 93 } 94 95 func (rv R[P]) Do(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 96 var x R[P] 97 return rv.Do(x) //@rename("Do", "Do2", DoToDo2) 98 } 99 100 func _() { 101 var x R[int] //@rename("R", "r", RTor) 102 x = x.Do(x) 103 } 104 105 -- @RTos/instances/type.go -- 106 @@ -3,2 +3,2 @@ 107 -type R[P any] struct { //@rename("R", "u", Rtou) 108 - Next *R[P] //@rename("R", "s", RTos) 109 +type s[P any] struct { //@rename("R", "u", Rtou) 110 + Next *s[P] //@rename("R", "s", RTos) 111 @@ -7,2 +7,2 @@ 112 -func (rv R[P]) Do(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 113 - var x R[P] 114 +func (rv s[P]) Do(s[P]) s[P] { //@rename("Do", "Do1", DoToDo1) 115 + var x s[P] 116 @@ -13 +13 @@ 117 - var x R[int] //@rename("R", "r", RTor) 118 + var x s[int] //@rename("R", "r", RTor) 119 -- @Rtou/instances/type.go -- 120 @@ -3,2 +3,2 @@ 121 -type R[P any] struct { //@rename("R", "u", Rtou) 122 - Next *R[P] //@rename("R", "s", RTos) 123 +type u[P any] struct { //@rename("R", "u", Rtou) 124 + Next *u[P] //@rename("R", "s", RTos) 125 @@ -7,2 +7,2 @@ 126 -func (rv R[P]) Do(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 127 - var x R[P] 128 +func (rv u[P]) Do(u[P]) u[P] { //@rename("Do", "Do1", DoToDo1) 129 + var x u[P] 130 @@ -13 +13 @@ 131 - var x R[int] //@rename("R", "r", RTor) 132 + var x u[int] //@rename("R", "r", RTor) 133 -- @DoToDo1/instances/type.go -- 134 @@ -7 +7 @@ 135 -func (rv R[P]) Do(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 136 +func (rv R[P]) Do1(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 137 @@ -9 +9 @@ 138 - return rv.Do(x) //@rename("Do", "Do2", DoToDo2) 139 + return rv.Do1(x) //@rename("Do", "Do2", DoToDo2) 140 @@ -14 +14 @@ 141 - x = x.Do(x) 142 + x = x.Do1(x) 143 -- @DoToDo2/instances/type.go -- 144 @@ -7 +7 @@ 145 -func (rv R[P]) Do(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 146 +func (rv R[P]) Do2(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 147 @@ -9 +9 @@ 148 - return rv.Do(x) //@rename("Do", "Do2", DoToDo2) 149 + return rv.Do2(x) //@rename("Do", "Do2", DoToDo2) 150 @@ -14 +14 @@ 151 - x = x.Do(x) 152 + x = x.Do2(x) 153 -- instances/func.go -- 154 package instances 155 156 func Foo[P any](p P) { //@rename("Foo", "Bar", FooToBar) 157 Foo(p) //@rename("Foo", "Baz", FooToBaz) 158 } 159 160 -- @FooToBar/instances/func.go -- 161 @@ -3,2 +3,2 @@ 162 -func Foo[P any](p P) { //@rename("Foo", "Bar", FooToBar) 163 - Foo(p) //@rename("Foo", "Baz", FooToBaz) 164 +func Bar[P any](p P) { //@rename("Foo", "Bar", FooToBar) 165 + Bar(p) //@rename("Foo", "Baz", FooToBaz) 166 -- @FooToBaz/instances/func.go -- 167 @@ -3,2 +3,2 @@ 168 -func Foo[P any](p P) { //@rename("Foo", "Bar", FooToBar) 169 - Foo(p) //@rename("Foo", "Baz", FooToBaz) 170 +func Baz[P any](p P) { //@rename("Foo", "Bar", FooToBar) 171 + Baz(p) //@rename("Foo", "Baz", FooToBaz) 172 -- @RTor/instances/type.go -- 173 @@ -3,2 +3,2 @@ 174 -type R[P any] struct { //@rename("R", "u", Rtou) 175 - Next *R[P] //@rename("R", "s", RTos) 176 +type r[P any] struct { //@rename("R", "u", Rtou) 177 + Next *r[P] //@rename("R", "s", RTos) 178 @@ -7,2 +7,2 @@ 179 -func (rv R[P]) Do(R[P]) R[P] { //@rename("Do", "Do1", DoToDo1) 180 - var x R[P] 181 +func (rv r[P]) Do(r[P]) r[P] { //@rename("Do", "Do1", DoToDo1) 182 + var x r[P] 183 @@ -13 +13 @@ 184 - var x R[int] //@rename("R", "r", RTor) 185 + var x r[int] //@rename("R", "r", RTor)