From 88569f5df7231a20f3a010efdce77dfd2e2c61bc Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Mon, 10 Aug 2020 16:32:05 +0200 Subject: [PATCH] fix: interface call regression from #787 Fix #787 changes how interfaces are set on a struct (compositeSparce). This change however makes calling the interface panic. This PR reverts part of the change in #787 and adds a test to ensure it does not break again. --- _test/interface46.go | 35 +++++++++++++++++++++++++++++++++++ interp/run.go | 2 -- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 _test/interface46.go diff --git a/_test/interface46.go b/_test/interface46.go new file mode 100644 index 00000000..fbb21152 --- /dev/null +++ b/_test/interface46.go @@ -0,0 +1,35 @@ +package main + +import "fmt" + +type I interface { + Foo() string +} + +type Printer struct { + i I +} + +func New(i I) *Printer { + return &Printer{ + i: i, + } +} + +func (p *Printer) Print() { + fmt.Println(p.i.Foo()) +} + +type T struct{} + +func (t *T) Foo() string { + return "test" +} + +func main() { + g := New(&T{}) + g.Print() +} + +// Output: +// test diff --git a/interp/run.go b/interp/run.go index 1e509778..ded67b14 100644 --- a/interp/run.go +++ b/interp/run.go @@ -2116,8 +2116,6 @@ 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):