mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
internal/lsp: return an error when renaming a builtin
Return an error when attempting to rename a builtin identifier. Fixes golang/go#32992 Change-Id: I7fb0f9cc9499e5afdfb14805c49c820e4da3b601 Reviewed-on: https://go-review.googlesource.com/c/tools/+/185246 Run-TryBot: Suzy Mueller <suzmue@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
c8855242db
commit
07655f7ec7
@ -46,10 +46,14 @@ func (i *IdentifierInfo) Rename(ctx context.Context, newName string) (map[span.U
|
||||
return nil, fmt.Errorf("invalid identifier to rename: %q", i.Name)
|
||||
}
|
||||
|
||||
// Do not rename identifiers declared in another package.
|
||||
if i.pkg == nil || i.pkg.IsIllTyped() {
|
||||
return nil, fmt.Errorf("package for %s is ill typed", i.File.URI())
|
||||
}
|
||||
// Do not rename builtin identifiers.
|
||||
if i.decl.obj.Parent() == types.Universe {
|
||||
return nil, fmt.Errorf("cannot rename builtin %q", i.Name)
|
||||
}
|
||||
// Do not rename identifiers declared in another package.
|
||||
if i.pkg.GetTypes() != i.decl.obj.Pkg() {
|
||||
return nil, fmt.Errorf("failed to rename because %q is declared in package %q", i.Name, i.decl.obj.Pkg().Name())
|
||||
}
|
||||
|
3
internal/lsp/testdata/rename/b/b.go
vendored
Normal file
3
internal/lsp/testdata/rename/b/b.go
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
package b
|
||||
|
||||
var c int //@rename("int", "uint")
|
2
internal/lsp/testdata/rename/b/b.go.golden
vendored
Normal file
2
internal/lsp/testdata/rename/b/b.go.golden
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
-- uint-rename --
|
||||
cannot rename builtin "int"
|
@ -34,7 +34,7 @@ const (
|
||||
ExpectedTypeDefinitionsCount = 2
|
||||
ExpectedHighlightsCount = 2
|
||||
ExpectedReferencesCount = 4
|
||||
ExpectedRenamesCount = 12
|
||||
ExpectedRenamesCount = 13
|
||||
ExpectedSymbolsCount = 1
|
||||
ExpectedSignaturesCount = 21
|
||||
ExpectedLinksCount = 2
|
||||
|
Loading…
Reference in New Issue
Block a user