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)
|
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() {
|
if i.pkg == nil || i.pkg.IsIllTyped() {
|
||||||
return nil, fmt.Errorf("package for %s is ill typed", i.File.URI())
|
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() {
|
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())
|
return nil, fmt.Errorf("failed to rename because %q is declared in package %q", i.Name, i.decl.obj.Pkg().Name())
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package b
|
||||||
|
|
||||||
|
var c int //@rename("int", "uint")
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- uint-rename --
|
||||||
|
cannot rename builtin "int"
|
|
@ -34,7 +34,7 @@ const (
|
||||||
ExpectedTypeDefinitionsCount = 2
|
ExpectedTypeDefinitionsCount = 2
|
||||||
ExpectedHighlightsCount = 2
|
ExpectedHighlightsCount = 2
|
||||||
ExpectedReferencesCount = 4
|
ExpectedReferencesCount = 4
|
||||||
ExpectedRenamesCount = 12
|
ExpectedRenamesCount = 13
|
||||||
ExpectedSymbolsCount = 1
|
ExpectedSymbolsCount = 1
|
||||||
ExpectedSignaturesCount = 21
|
ExpectedSignaturesCount = 21
|
||||||
ExpectedLinksCount = 2
|
ExpectedLinksCount = 2
|
||||||
|
|
Loading…
Reference in New Issue