You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x/tools/gopls: 'implementations' doesn't work with genericsΒ #59224
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:
xtools$ cat d/d.go
package d
type Collection[T any] interface {
Push(T) error
Pop() (*T, bool)
}
type C[T any] struct{}
func (C[T]) Push(t T) error { return nil }
func (C[T]) Pop() (*T, bool) {
var t T
return &t, true
}
var _ Collection[int] = C[int]{}
xtools$ go run ./gopls implementation ./d/d.go:#120 # within "Push" concrete method identifier
xtools$
/Users/.../go/go1.23.4/bin/go install golang.org/x/tools/gopls@master
go: golang.org/x/tools/gopls@master (in golang.org/x/tools/gopls@v0.0.0-20250124010602-45227b6df520):
The go.mod file for the module providing named packages contains one or
more replace directives. It must not contain directives that would cause
it to be interpreted differently than if it were the main module.
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 type T struct { io.Reader } appearing with in a function will not be found be a query for implementations of io.Reader. Also, gopls' matching algorithm for generic types and instantiations is not perfectly accurate.
Activity
linjunhao1997 commentedon Apr 1, 2023
I think this is urgently needed
fangjh13 commentedon May 29, 2023
I would like to know how the progress is going, it's really needed.
adonovan commentedon May 30, 2023
No progress, sorry. Haven't even designed the algorithm yet. But let's make it a priority for 0.13.
14 remaining items
gopherbot commentedon Dec 9, 2024
Change https://go.dev/cl/634597 mentions this issue:
internal/typeparams: delete GenericAssignableTogopherbot commentedon Dec 9, 2024
Change https://go.dev/cl/634596 mentions this issue:
gopls/internal/golang: Implementations: support genericsinternal/typeparams: delete GenericAssignableTo
gopls/internal/cache/methodsets: support generics
gopls/internal/golang: Implementations: support generics
DingYuan0118 commentedon Jan 24, 2025
Hello, half year passed. Any progress on this one?
adonovan commentedon Jan 24, 2025
Yes! Run
go install golang.org/x/tools/gopls@masterand let us know how this feature works for you.DingYuan0118 commentedon Jan 24, 2025
Thanks for the quick response.
And I have got a question. I found that the Goland IDE already have a similar func like
Is there any difference between it and gopls?
DingYuan0118 commentedon Jan 24, 2025
reports
adonovan commentedon Jan 24, 2025
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
type T struct { io.Reader }appearing with in a function will not be found be a query for implementations ofio.Reader. Also, gopls' matching algorithm for generic types and instantiations is not perfectly accurate.Ah, sorry about that, our go.mod file uses a replace directive so you can't
go installdirect from master, only tagged releases.You'll need to
git clone https://go.googlesource.com/toolsand thencd goplsandgo install.DingYuan0118 commentedon Jan 24, 2025
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...
adonovan commentedon Jan 24, 2025
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.