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:
9
_test/d1/d1.go
Normal file
9
_test/d1/d1.go
Normal 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
8
_test/d2/d2.go
Normal 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
11
_test/d3.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import "github.com/traefik/yaegi/_test/d2"
|
||||
|
||||
func main() {
|
||||
f := d2.F
|
||||
f()
|
||||
}
|
||||
|
||||
// Output:
|
||||
// test
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user