On Saturday, October 1, 2016 at 10:07:02 PM UTC+8, Jan Mercl wrote: > > > > but we even don't know how the builtin byte and uint8 are defined? > > Yes we know, see: https://golang.org/ref/spec#Numeric_types >
I know this byte and uint8 are identical in syntax. But they are not defined with TypeSpec <https://golang.org/ref/spec#Type_declarations> style described in the go spec. In addition to there is no ways to define identical custom named types, so I think the text "Two named types <https://golang.org/ref/spec#Types> are identical if their type names originate in the same TypeSpec <https://golang.org/ref/spec#Type_declarations>." in go spec is meaningless. Sorry, my English is not good, I have tried my best to explain my opinion. > > > How do you know their type names originate in the same TypeSpec? > <https://golang.org/ref/spec#Type_declarations> > > Because that's how the semantics of predeclared aliases are specified, > regardless of no real source code definition for the type specification > exists. > > Let's assume named types byte and uint8 do not share the same type > specification. So the compiler must reject this code ( > https://play.golang.org/p/EtiJNC_NIZ): > > package main > > func main() { > var b byte > var u uint8 > b = u > _ = b > } > > It compiles just fine. OTOH this code ( > https://play.golang.org/p/Jq9eEGGUwy): > > package main > > type uint8 byte > > func main() { > var b byte > var u uint8 > b = u > _ = b > } > > > Is rejected because the types are not identical and assignability rules ( > https://golang.org/ref/spec#Assignability) demand that when both sides > are named types. > > Q.E.D. > > -- > > -j > -- 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. For more options, visit https://groups.google.com/d/optout.