On Fri, Mar 10, 2017 at 7:19 AM, Henry <[email protected]> wrote: > > Thanks for the reply. I will rephrase the question. See the code > illustration in the first post if you did not follow the discussion from the > beginning. > > a.Arg and b.Arg are identical interfaces living in different packages: > package a and package b respectively. Type X that implements a.Arg is > automatically assignable to b.Arg. In fact, you can use X as a parameter to > either Work(a.Arg) and Work(b.Arg) without any problem. This implies that > a.Arg and b.Arg are identical from assignability perspective and the > compiler can recognize this. However, the compiler does not think > Work(a.Arg) and Work(b.Arg) as identical even though a.Arg and b.Arg are > identical (assignable to each other). a.Worker interface that has > Work(a.Arg) is not assignable to b.Worker interface that has Work(b.Arg). I > wonder why.
Type identity and type assignability are not the same thing in Go. In the language spec type identity is defined at https://golang.org/ref/spec#Type_identity . Type assignability is https://golang.org/ref/spec#Assignability . As you can see from reading those, assignability is a superset of identity. Method sets require identity, not assignability. Your question is a variant of the FAQ answered at https://golang.org/doc/faq#covariant_types . Ian -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
