Closed rndz closed 3 weeks ago
The crash also seems to occur whenever the new name is a builtin name, e.g. gorename -from 'main.go::world' -to len
.
The crash also seems to occur whenever the new name is a builtin name
Actually, real
is a builtin.
In contrast to renaming to builtins which cause crashes, renaming to keywords is handled gracefully:
$ gorename -from 'main.go:: world' -to else
gorename: -to "else": not a valid identifier
See isValidIdentifier
-> token.Lookup
/cc @alandonovan
We can improve gorename by handling rename to builtins the same way as keywords are handled. It should return this error: gorename: -to "len": not a valid identifier
Renames to built-in names should not be handled specially. There are plenty of occasions when you want to re-use a predeclared name, such as a function called print or real, or a method called int or string.
The tool should not crash, of course.
closing as obsoleted by #69360
Thanks @seankhliao. Do beware that many of these gorename issues are in principle applicable to gopls' Rename LSP RPC, which runs a fork of the same algorithm. That said, I just verified that this particular issue is fixed in gopls, and that the other ones just closed don't really apply to gopls because it has a notion of a workspace.
What did you do?
While trying to rename a variable (func, etc..) to
real
the gorename tool panics.Suppose you have a
main.go
like this:And you run
gorename -from 'main.go::world' -to real
What did you expect to see?
Expected output:
Renamed 2 occurrences in 1 file in 1 package.
and the
main.go
file containing:What did you see instead?
System details