It's part of the language specifications https://golang.org/ref/spec#Types. 
It says:
type (
  B1 string
  B2 B1
)

"The underlying type of [...] B1 and B2 is string"

In other words, when you write 
type X time.Time
there is absolutely *no direct* connection between the types X and 
time.Time:
the only connection is that they both have the same *underlying* type, 
which is some unnamed struct, as you wrote.

On Tuesday, November 19, 2019 at 7:10:44 PM UTC+1, Stephen Searles wrote:
>
> I'm not sure if this could be considered a bug or not, but it's 
> unfortunate behavior for certain patterns of type analysis. The problem is 
> with a type like:
>
> type X time.Time
>
> When you inspect type X, you find that it is analyzed as a types.Named. 
> Its immediate underlying type is a types.Struct. I have a few problems with 
> this:
>
>    - This hides the fact that there is more information about type X 
>    available (time.Time's documentation) 
>    - This makes the location and identity of the actual struct definition 
>    hard to find because the types.Struct is not an object that you can find 
>    the source position of
>    - The dependency relationship between these types is not obvious (as 
>    in, changing/renaming time.Time will affect the program using X, but not 
>    the other way around)
>
> Here's a small demo of the situation described here: 
> https://play.golang.org/p/oqYRDIO7kmf
>
> Please let me know if I'm something missing, but as it stands, I think the 
> only way around these issues would be to analyze the syntax of every 
> defined type to check if it's got an underlying name or not. Does this 
> sound like something that could be safely improved within go/types? 
>
> Thanks,
> Stephen
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b5bf0606-cd00-4299-b52f-804b2993efcd%40googlegroups.com.

Reply via email to