This does not work for the same reason []*MyType cannot be converted to []MyInterface or even to []interface{}: the in-memory representation of an interface is not the same as of the concrete type. See also https://golang.org/doc/faq#convert_slice_of_interface > On Nov 1, 2016, at 6:54 AM, Steven Hartland <ste...@multiplay.co.uk> wrote: > > I was playing with a design today where I had a number of types which match > an interface and was surprised that I couldn't make use of this fact in > passing their new functions into a method. > > It seems that even though the returned type matches the interface within the > function argument go doesn't do the coercion needed to make this happen, > instead if errors: > cannot use NewMyType (type func() (*MyType, error)) as type func() > (MyInterface, error) in argument to wibble. > > Here MyType satisfies MyInterface, a full example can be seen here: > https://play.golang.org/p/r27a081joD <https://play.golang.org/p/r27a081joD> > > My workaround is currently to run the function and pass the results in, but > that seems like it should be unnecessary. > var i MyInterface > var err error > i, err = NewMyType() > wibble(i, err) > > Where wibble is: > func wibble(i MyInterface, err error) { > ... > } > > I can't see any reason why this wouldn't be supported, so possibly a future > version could make this possible? > > Regards > Steve > > -- > 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 > <mailto:golang-nuts+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>.
-- 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.