-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Forked from #19412 (comment), to continue discussion with @jimmyfrasche and any others without taking over that proposal thread.
The pattern of having an interface with an unexported method and types that implement it is a fairly common pattern in Go as we don't have sum types. A good example is in go/ast
: https://golang.org/pkg/go/ast/#Spec
For a user reading the godoc, it's very useful to them to know what are the types that can go in that interface. The actual information is hidden in the code, so most packages like go/ast
above list them manually: The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.
This works OK, but the issue is that these names aren't linked to the types in the same page. I propose that this happen automatically, much like #4953 for packages. Linking to types (and potentially other exported names like funcs and consts) could be useful for other purposes.
This is the conservative solution. A more aggressive solution would be to automatically generate the list of types that can fit into the interface. If we had sum types that could be limited to those kinds of types and be trivial to implement.
As long as we don't have sum types, @jimmyfrasche was suggesting to just list all the types that satisfy the interface in its package. I'm not sure if that's a good idea for all interfaces, but would certainly be useful for those that follow the pattern of an unexported method to mimic sum types. Not sure how safe/desired such a change would be.
Manually listing the types in the godoc isn't a huge pain, but not having links is a problem.
CC @griesemer who wrote the go/ast
godoc and might have some input