interp: fix receiver for exported method objects

When a function variable is assigned from an exported method,
make sure the receiver is updated from the coresponding symbol.

Fixes #1182.
This commit is contained in:
Marc Vertes
2021-07-13 11:00:14 +02:00
committed by GitHub
parent 4fcf90edae
commit 13d554acbe
4 changed files with 29 additions and 0 deletions

9
_test/d1/d1.go Normal file
View File

@@ -0,0 +1,9 @@
package d1
type T struct {
Name string
}
func (t *T) F() { println(t.Name) }
func NewT(s string) *T { return &T{s} }

8
_test/d2/d2.go Normal file
View File

@@ -0,0 +1,8 @@
package d2
import "github.com/traefik/yaegi/_test/d1"
var (
X = d1.NewT("test")
F = X.F
)

11
_test/d3.go Normal file
View File

@@ -0,0 +1,11 @@
package main
import "github.com/traefik/yaegi/_test/d2"
func main() {
f := d2.F
f()
}
// Output:
// test

View File

@@ -1503,6 +1503,7 @@ func (interp *Interpreter) cfg(root *node, importPath string) ([]*node, error) {
n.action = aGetSym
n.typ = sym.typ
n.sym = sym
n.recv = sym.recv
n.rval = sym.rval
} else {
err = n.cfgErrorf("undefined selector: %s.%s", pkg, name)