Skip to content

Commit

Permalink
interp: fix receiver for exported method objects
Browse files Browse the repository at this point in the history
When a function variable is assigned from an exported method,
make sure the receiver is updated from the coresponding symbol.

Fixes #1182.
  • Loading branch information
mvertes committed Jul 12, 2021
1 parent 78d7e85 commit 9356fab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions _test/d1/d1.go
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions _test/d2/d2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package d2

import "github.com/traefik/yaegi/_test/d1"

var (
X = d1.NewT("test")
F = X.F
)
11 changes: 11 additions & 0 deletions _test/d3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "github.com/traefik/yaegi/_test/d2"

func main() {
f := d2.F
f()
}

// Output:
// test
1 change: 1 addition & 0 deletions interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9356fab

Please sign in to comment.