Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: References: "KeyOf(%s)={} yet %s is a method" bug in expandMethodSearch when a field and method conflict (via telemetry) #68817

Closed
adonovan opened this issue Aug 9, 2024 · 4 comments
Assignees
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Aug 9, 2024

This stack WrwN7A was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Errorf:+2
golang.org/x/tools/gopls/internal/golang.expandMethodSearch:+4
golang.org/x/tools/gopls/internal/golang.ordinaryReferences:+137
golang.org/x/tools/gopls/internal/golang.references:+14
golang.org/x/tools/gopls/internal/golang.References:+1
golang.org/x/tools/gopls/internal/server.(*server).References:+18
golang.org/x/tools/gopls/internal/protocol.serverDispatch:+478
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3
runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.1 go1.22.4 darwin/arm64 vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels Aug 9, 2024
@gopherbot gopherbot added this to the Unreleased milestone Aug 9, 2024
@adonovan
Copy link
Member Author

So KeyOf(recv) returns hasMethods = false. This means methodSetInfo returned Mask=0. The Mask has at least one bit set if the loop executes at all, so NewMethodSet(EnsurePointer(t)) must indeed be empty. How can the method set of a type be empty if the query started from a method of that type? Hmm... what if there are two methods, or a field and a method, that conflict?

$ cat a.go
package p

type E struct { X int }
func (E) X() {} // offset #45 is "X"

$ gopls references ./a.go:#45
gopls: KeyOf(*golang.org/x/tools.E)={} yet func (golang.org/x/tools.E).X() is a method
exit status 2

Bingo.

@adonovan adonovan changed the title x/tools/gopls: References: "KeyOf(%s)={} yet %s is a method" bug in expandMethodSearch (via telemetry) x/tools/gopls: References: "KeyOf(%s)={} yet %s is a method" bug in expandMethodSearch when a field and method conflict (via telemetry) Aug 12, 2024
@adonovan adonovan self-assigned this Aug 12, 2024
@adonovan
Copy link
Member Author

Dup of #67978.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/605015 mentions this issue: gopls/internal/golang: downgrade assertion in methodsets index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants