-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: 'implementations' doesn't work with generics #59224
Comments
I think this is urgently needed |
I would like to know how the progress is going, it's really needed. |
No progress, sorry. Haven't even designed the algorithm yet. But let's make it a priority for 0.13. |
Hello, is a fix for this planned in the upcoming release ? |
I'm also currently googling / gpting / searching, atm I have to make tests on a struct to verify that I've created structs according to generic interface in neovim. |
Unfortunately no, but likely the following one. |
Hello any progress on this one? |
Still no progress yet, sorry. The problem is a little trickier than it may appear because of the design of the index (database) used to radically optimize gopls v0.15. The indexed design means that the problem of testing implements(T, I), where I is an interface, cannot be done by making queries on the type-checker data structures for T and I since we no longer have them. Instead, the problem is mapped onto the domain of sets of strings, each representing a single method, so that the query becomes a string subset test. This works well for non-generic methods, which can each be mapped to a special string called a fingerprint; but we have not yet had time to develop a theory for fingerprinting generic methods, so they would need to fall back to using the type-checker, undoing the benefits of the gopls v0.15 redesign. Of course there are various short-cuts we could apply for common and simple cases, but our current focus is on better support for refactoring, so unfortunately this is not going to happen in the next several months. |
Change https://go.dev/cl/634197 mentions this issue: |
Change https://go.dev/cl/634597 mentions this issue: |
Change https://go.dev/cl/634596 mentions this issue: |
It is unused and, in the one place we actually wanted to use it, it was the wrong tool for the job; what we need is unification. Updates golang/go#59224 Updates golang/go#63982 Change-Id: I05b6fe6f56e3f81f434e76398c20496950822bfb Reviewed-on: https://go-review.googlesource.com/c/tools/+/634597 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
This CL adds support to gopls' index of methodsets to enable matching of generic types and their methods. Previously, the index was based on the notion of "fingerprints", strings that encode the type of a method such that fingerprints are equal if and only if types are equal. Of course this does not work for generic types, which can match multiple distinct types. This change redesigns the fingerprint encoding so that it preserves the tree structure of the type, allowing it to be parsed again later, supporting tree-based matching such as unification. (The encoding is about 30% bigger.) The actual tree matching in this CL is very simple: each type parameter is treated as a wildcard that can match any subtree at all, without regard to consistency of substitution (as in true unification), nor to type parameter constraint satisfaction. Full unification would reduce false positives, but is not urgently needed. This CL addresses only the global algorithm using the methodsets index. See CL 634596 for the local (type-based) algorithm. + Test, relnote, doc Updates golang/go#59224 Change-Id: I670511a8e5ce02ab23ff7b7bd60e7bd7b43c1cca Reviewed-on: https://go-review.googlesource.com/c/tools/+/634197 Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
Hello, half year passed. Any progress on this one? |
Yes! Run |
reports
|
I don't use goland, so I can't answer that question. I am sure the feature is similar in the broad strokes (connecting interfaces with implementations), but it may differ in the details. For example, gopls only reports package-level types from other packages, so a type such as
Ah, sorry about that, our go.mod file uses a replace directive so you can't You'll need to |
It works good for this demo. But our project can not upgrade go version so quickly and still use go1.19. So it is a little painful that I can not use this feature... |
go1.19? That's very old: gopls v0.15 dropped support for go1.19 last April. You should find a way to upgrade your project. |
Even some of the most basic scenarios of 'implementations' are not working at all with generics, for example when the concrete and interface types are both generalized over
[T any]
and are defined within the same file:This is not a recent regression:
A similar lack of results is obtained by querying the
Push
abstract method, or the Collection interface, or the C concrete type.(This test case was a further reduction of the one described in https://youtrack.jetbrains.com/issue/GO-12702/Go-to-Declaration-Implementation-not-available-for-generics-interfaces, referenced by golang/vscode-go#2711.)
The text was updated successfully, but these errors were encountered: