Skip to content

x/tools/gopls: spurious "would shadow" error when renaming parameter #57479

@adonovan

Description

@adonovan

When renaming a parameter using gopls's rename command, and the new name is identical to the name of an imported package referenced by one of the function parameters, gopls reports an error, even though the renaming might be sound. For example:

import "fmt"

func _(x fmt.Stringer) {} // rename x to "fmt" gives renaming this var "x" to "fmt" would shadow this reference to the imported package name declared here

(Unfortunately the pronouns in the error message don't actually link to source locations, at least not when I use Emacs+eglot.)

The same thing happens when the package is referenced by a later parameter (e.g. func(x int, y fmt.Stringer)) or by a named constant in an array type (e.g. func(x [math.MaxInt]bool)).

IIRC the gorename tool got this right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RefactoringIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions