-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/lsp/source: fix renaming of type parameters
Type parameters were incorrectly being treated as exported for the purpose of renaming checks, and imported type parameters do not have the correct scope information for rename checks to work. Fixes golang/go#61635 Change-Id: I4261c5e7b3622affbeb81a96ea4f510a5b9e4fe3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/513916 gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
- Loading branch information
Showing
3 changed files
with
124 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
gopls/internal/regtest/marker/testdata/rename/generics.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
This test exercises various renaming features on generic code. | ||
|
||
Fixed bugs: | ||
|
||
- golang/go#61614: renaming a method of a type in a package that uses type | ||
parameter composite lits used to panic, because previous iterations of the | ||
satisfy analysis did not account for this language feature. | ||
|
||
- golang/go#61635: renaming type parameters did not work when they were | ||
capitalized and the package was imported by another package. | ||
|
||
-- flags -- | ||
-min_go=go1.18 | ||
|
||
-- go.mod -- | ||
module example.com | ||
go 1.20 | ||
|
||
-- a.go -- | ||
package a | ||
|
||
type I int | ||
|
||
func (I) m() {} //@rename("m", M, mToM) | ||
|
||
func _[P ~[]int]() { | ||
_ = P{} | ||
} | ||
|
||
-- @mToM/a.go -- | ||
package a | ||
|
||
type I int | ||
|
||
func (I) M() {} //@rename("m", M, mToM) | ||
|
||
func _[P ~[]int]() { | ||
_ = P{} | ||
} | ||
|
||
-- g.go -- | ||
package a | ||
|
||
type S[P any] struct { //@rename("P", Q, PToQ) | ||
P P | ||
F func(P) P | ||
} | ||
|
||
func F[R any](r R) { | ||
var _ R //@rename("R", S, RToS) | ||
} | ||
|
||
-- @PToQ/g.go -- | ||
package a | ||
|
||
type S[Q any] struct { //@rename("P", Q, PToQ) | ||
P Q | ||
F func(Q) Q | ||
} | ||
|
||
func F[R any](r R) { | ||
var _ R //@rename("R", S, RToS) | ||
} | ||
|
||
-- @RToS/g.go -- | ||
package a | ||
|
||
type S[P any] struct { //@rename("P", Q, PToQ) | ||
P P | ||
F func(P) P | ||
} | ||
|
||
func F[S any](r S) { | ||
var _ S //@rename("R", S, RToS) | ||
} | ||
|
||
-- issue61635/p.go -- | ||
package issue61635 | ||
|
||
type builder[S ~[]F, F ~string] struct { //@rename("S", T, SToT) | ||
name string | ||
elements S | ||
elemData map[F][]ElemData[F] | ||
// other fields... | ||
} | ||
|
||
type ElemData[F ~string] struct { | ||
Name F | ||
// other fields... | ||
} | ||
|
||
type BuilderImpl[S ~[]F, F ~string] struct{ builder[S, F] } | ||
|
||
-- importer/i.go -- | ||
package importer | ||
|
||
import "example.com/issue61635" // importing is necessary to repro golang/go#61635 | ||
|
||
var _ issue61635.ElemData[string] | ||
|
||
-- @SToT/issue61635/p.go -- | ||
package issue61635 | ||
|
||
type builder[T ~[]F, F ~string] struct { //@rename("S", T, SToT) | ||
name string | ||
elements T | ||
elemData map[F][]ElemData[F] | ||
// other fields... | ||
} | ||
|
||
type ElemData[F ~string] struct { | ||
Name F | ||
// other fields... | ||
} | ||
|
||
type BuilderImpl[S ~[]F, F ~string] struct{ builder[S, F] } | ||
|
35 changes: 0 additions & 35 deletions
35
gopls/internal/regtest/marker/testdata/rename/issue61614.txt
This file was deleted.
Oops, something went wrong.