diff --git a/_test/issue-776.go b/_test/issue-776.go new file mode 100644 index 00000000..7dce6534 --- /dev/null +++ b/_test/issue-776.go @@ -0,0 +1,39 @@ +package main + +import "fmt" + +// Filter is a filter +type Filter interface { + Foo() +} + +// GIFT is a gift +type GIFT struct { + Filters []Filter +} + +// New is a new filter list +func New(filters ...Filter) *GIFT { + return &GIFT{ + Filters: filters, + } +} + +// List lists filters +func (g *GIFT) List() { + fmt.Printf("Hello from List!\n") +} + +// MyFilter is one of the filters +type MyFilter struct{} + +// Foo is a foo +func (f *MyFilter) Foo() {} + +func main() { + g := New(&MyFilter{}) + g.List() +} + +// Output: +// Hello from List! diff --git a/interp/run.go b/interp/run.go index a1ee5514..bc435ba5 100644 --- a/interp/run.go +++ b/interp/run.go @@ -2116,6 +2116,10 @@ func doCompositeSparse(n *node, hasType bool) { switch { case c1.typ.cat == funcT: values[field] = genFunctionWrapper(c1) + case c1.typ.cat == interfaceT: + values[field] = genValueInterfaceValue(c1) + case isArray(c1.typ) && c1.typ.val != nil && c1.typ.val.cat == interfaceT: + values[field] = genValueInterfaceArray(c1) case isRecursiveType(n.typ.field[field].typ, n.typ.field[field].typ.rtype): values[field] = genValueRecursiveInterface(c1, n.typ.field[field].typ.rtype) default: diff --git a/interp/type.go b/interp/type.go index 39cfc16b..53a25d56 100644 --- a/interp/type.go +++ b/interp/type.go @@ -1541,6 +1541,10 @@ func isSendChan(t *itype) bool { return rt.Kind() == reflect.Chan && rt.ChanDir() == reflect.SendDir } func isMap(t *itype) bool { return t.TypeOf().Kind() == reflect.Map } +func isArray(t *itype) bool { + k := t.TypeOf().Kind() + return k == reflect.Array || k == reflect.Slice +} func isInterfaceSrc(t *itype) bool { return t.cat == interfaceT || (t.cat == aliasT && isInterfaceSrc(t.val))