-
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.
internal/lsp/source: canonicalize objects in reference/rename requests
With generics, instantiated object may have differing pointer identities. Fix references/rename requests for instantiated methods/fields by using a canonical object identity of (pos, pkg, name). Fixes golang/go#51672 Change-Id: I0021ca562b8a74dadb616cf6864cb0bdd0165cc3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/392480 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
- Loading branch information
Showing
8 changed files
with
204 additions
and
5 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
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,10 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type foo[P any] int //@rename("foo","bar") | ||
|
||
var x struct{ foo[int] } | ||
|
||
var _ = x.foo |
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,12 @@ | ||
-- bar-rename -- | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type bar[P any] int //@rename("foo","bar") | ||
|
||
var x struct{ bar[int] } | ||
|
||
var _ = x.bar | ||
|
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,25 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type G[P any] struct { | ||
F int | ||
} | ||
|
||
func (G[_]) M() {} | ||
|
||
func F[P any](P) { | ||
var p P //@rename("P", "Q") | ||
_ = p | ||
} | ||
|
||
func _() { | ||
var x G[int] //@rename("G", "H") | ||
_ = x.F //@rename("F", "K") | ||
x.M() //@rename("M", "N") | ||
|
||
var y G[string] | ||
_ = y.F | ||
y.M() | ||
} |
108 changes: 108 additions & 0 deletions
108
internal/lsp/testdata/rename/generics/generics.go.golden
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,108 @@ | ||
-- Q-rename -- | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type G[P any] struct { | ||
F int | ||
} | ||
|
||
func (G[_]) M() {} | ||
|
||
func F[Q any](Q) { | ||
var p Q //@rename("P", "Q") | ||
_ = p | ||
} | ||
|
||
func _() { | ||
var x G[int] //@rename("G", "H") | ||
_ = x.F //@rename("F", "K") | ||
x.M() //@rename("M", "N") | ||
|
||
var y G[string] | ||
_ = y.F | ||
y.M() | ||
} | ||
|
||
-- H-rename -- | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type H[P any] struct { | ||
F int | ||
} | ||
|
||
func (H[_]) M() {} | ||
|
||
func F[P any](P) { | ||
var p P //@rename("P", "Q") | ||
_ = p | ||
} | ||
|
||
func _() { | ||
var x H[int] //@rename("G", "H") | ||
_ = x.F //@rename("F", "K") | ||
x.M() //@rename("M", "N") | ||
|
||
var y H[string] | ||
_ = y.F | ||
y.M() | ||
} | ||
|
||
-- K-rename -- | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type G[P any] struct { | ||
K int | ||
} | ||
|
||
func (G[_]) M() {} | ||
|
||
func F[P any](P) { | ||
var p P //@rename("P", "Q") | ||
_ = p | ||
} | ||
|
||
func _() { | ||
var x G[int] //@rename("G", "H") | ||
_ = x.K //@rename("F", "K") | ||
x.M() //@rename("M", "N") | ||
|
||
var y G[string] | ||
_ = y.K | ||
y.M() | ||
} | ||
|
||
-- N-rename -- | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type G[P any] struct { | ||
F int | ||
} | ||
|
||
func (G[_]) N() {} | ||
|
||
func F[P any](P) { | ||
var p P //@rename("P", "Q") | ||
_ = p | ||
} | ||
|
||
func _() { | ||
var x G[int] //@rename("G", "H") | ||
_ = x.F //@rename("F", "K") | ||
x.N() //@rename("M", "N") | ||
|
||
var y G[string] | ||
_ = y.F | ||
y.N() | ||
} | ||
|
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,10 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type T string //@rename("T", "R") | ||
|
||
type C interface { | ||
T | ~int //@rename("T", "S") | ||
} |
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,24 @@ | ||
-- R-rename -- | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type R string //@rename("T", "R") | ||
|
||
type C interface { | ||
R | ~int //@rename("T", "S") | ||
} | ||
|
||
-- S-rename -- | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package generics | ||
|
||
type S string //@rename("T", "R") | ||
|
||
type C interface { | ||
S | ~int //@rename("T", "S") | ||
} | ||
|
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