The rules of type identity state that:
Two named types are identical if their type names originate in the same TypeSpec
I don't quite understand how two type names originate in the same TypeSpec. Can you explain it or show me an example?
Only one type name can originate from a TypeSpec. That's kind of the point. So
type Foo int64
var x Foo
var y Foo
then both Foos originate in the same TypeSpec, so they are identical Foos.
However, if you have two different files (in different packages):
a.go:
type Foo int64
var x Foo
b.go:
type Foo int64
var y Foo
Then the two Foos in this situation are not identical. Even though they are the same type name, they originated from different TypeSpecs. The consequence of this is that the types of x and y are not identical (and thus x = y without a cast is not allowed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With