Hi all!
I've encountered a limitation and I'd like to understand what's going on and why it's not working the way I would expect.
If I have a slice of an interface type, and another slice of a type that implements that interface, I cannot concat these slices together using append - but I can add each item one by one.
I would expect that interface implementations would also apply to slices, but it looks like it doesn't?
package main
type IExample interface {
Foo() string
}
type TBar struct{}
func (t TBar) Foo() string {
return ""
}
func main() {
examples := []IExample{}
bars := []TBar{TBar{}, TBar{}}
// Works
for _, bar := range bars {
examples = append(examples, bar)
}
// Does not work
examples = append(examples, bars...)
// ./prog.go:23:30: cannot use bars (variable of type []TBar) as []IExample value in argument to append
}