Skip to content

Commit

Permalink
fix: do not hide receiver type for method with anonymous receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Oct 19, 2019
1 parent 0b4dcbf commit 7164a23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions _test/method28.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import "fmt"

type T struct {
Name string
}

func (T) create() *T {
return &T{"Hello"}
}

func main() {
fmt.Println(T{}.create())
}

// Output:
// &{Hello}
9 changes: 6 additions & 3 deletions interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,16 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
if len(n.child[0].child) > 0 {
// define receiver symbol
var typ *itype
recvName := n.child[0].child[0].child[0].ident
recvTypeNode := n.child[0].child[0].lastChild()
fr := n.child[0].child[0]
recvTypeNode := fr.lastChild()
if typ, err = nodeType(interp, sc, recvTypeNode); err != nil {
return false
}
recvTypeNode.typ = typ
sc.sym[recvName] = &symbol{index: sc.add(typ), kind: varSym, typ: typ}
index := sc.add(typ)
if len(fr.child) > 1 {
sc.sym[fr.child[0].ident] = &symbol{index: index, kind: varSym, typ: typ}
}
}
for _, c := range n.child[2].child[0].child {
// define input parameter symbols
Expand Down

0 comments on commit 7164a23

Please sign in to comment.