This is answered in the FAQ: https://golang.org/doc/faq#covariant_types
On Mon, May 24, 2021 at 8:21 AM Amnon <[email protected]> wrote: > See https://play.golang.org/p/5x9JrD55WKc > > The interfaces aer and ber look equivalent. > Both contain a function which returns nothing called m1 > and a function which returns another an instance of the interface m2. > > If we comment out m2, then the code will compile. > But otherwise we get an error: > > ./prog.go:14:5: cannot use a (type aer) as type ber in argument to bar: > aer does not implement ber (wrong type for m2 method) have m2() aer want > m2() ber > > even though aer and ber should be equivalent! > > package main > > type aer interface { > m1() > m2() aer > } > > type ber interface { > m1() > m2() ber > } > > func Foo(a aer) { > bar(a) > } > > func bar(b ber) { > } > > func main() { > } > > -- > 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]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/4112dd4a-f2b3-4469-806e-233f242f93f9n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/4112dd4a-f2b3-4469-806e-233f242f93f9n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfEZHGJ9VHTHq3e-R9HsYsoXW5aywLRgCPhnE9GXub8MYA%40mail.gmail.com.
