Thanks for the response. I understand that what I'm asking is a bit beyond the scope of what a compiler would need to correctly implement the language, which is what the spec details. The question/request here is more about usability of the types package for purposes that are more human/developer-driven, like documentation and static analysis. For purposes like these, having some way to associate the types would be helpful, because while there is no "direct" connection that the compiler would care about, there is absolutely an "indirect" connection that humans or other tools may care about.
The fact that the types are not hierarchically related actually underscores why this matters. Picking on time.Time still: one might create a new type based on time.Time to handle a detail like (un)marshaling to the
correct time.Location,
given that such information is not conveyed by any of the formats supported by the time package. Making it easy to see that such a type is underlied by time.Time would make it easier for tools to, say, identify that this code should be checked for correctness with regard to timezones. I could imagine other use cases of this kind of association in things like security scanning or searching for usage of possible PII (for GDPR/privacy compliance).
The only way I see is to accomplish this right now is to inspect the AST. It's surprisingly complicated and feels a little silly because I'd bet I'm repeating work that the types package (and friends) already did. Here's implementing such a lookup for my toy example:
https://play.golang.org/p/Ph7YV0a8JU4. Is there something I'm missing that could make this simpler?
Thinking about possible solutions, changing the behavior of the types.Named.Underlying() method seems like the naive approach. I would guess that returning an underlying types.Named would be considered a breaking change. It wouldn't change the method signature, but it would break code that currently assumes the value returned there is a more concrete type. Adding a method like
func (Named) UnderlyingName() *Named
could work, but I also see some downsides of that approach, like that it proliferates API in an already complex package. Adding something to types.Info might be the most reasonable option, to reduce the impact of such an addition.
Thanks again,
Stephen