-
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 incorrect 'origin' logic for named types
Type names of named types are always canonical. The existing logic to canonicalize them was ineffective, and had the side effect of breaking aliases. Also add more tests of generic name renaming. Fixes golang/go#61625 Change-Id: I318a758176aea6712da16dde29394ffb08bdf715 Reviewed-on: https://go-review.googlesource.com/c/tools/+/513917 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]>
- Loading branch information
Showing
3 changed files
with
149 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,17 +343,15 @@ func renameOrdinary(ctx context.Context, snapshot Snapshot, f FileHandle, pp pro | |
// Find objectpath, if object is exported ("" otherwise). | ||
var declObjPath objectpath.Path | ||
if obj.Exported() { | ||
// objectpath.For requires the origin of a generic | ||
// function or type, not an instantiation (a bug?). | ||
// Unfortunately we can't call {Func,TypeName}.Origin | ||
// as these are not available in go/[email protected]. | ||
// So we take a scenic route. | ||
// objectpath.For requires the origin of a generic function or type, not an | ||
// instantiation (a bug?). Unfortunately we can't call Func.Origin as this | ||
// is not available in go/[email protected]. So we take a scenic route. | ||
// | ||
// Note that unlike Funcs, TypeNames are always canonical (they are "left" | ||
// of the type parameters, unlike methods). | ||
switch obj.(type) { // avoid "obj :=" since cases reassign the var | ||
case *types.TypeName: | ||
switch t := obj.Type().(type) { | ||
case *types.Named: | ||
obj = t.Obj() | ||
case *typeparams.TypeParam: | ||
if _, ok := obj.Type().(*typeparams.TypeParam); ok { | ||
// As with capitalized function parameters below, type parameters are | ||
// local. | ||
goto skipObjectPath | ||
|
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