Skip to content

Commit

Permalink
fix: correct type extraction for returned value
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Dec 17, 2019
1 parent 4f93be7 commit e1ac83f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
15 changes: 15 additions & 0 deletions _test/nil0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import "fmt"

func f() (host, port string, err error) {
return "", "", nil
}

func main() {
h, p, err := f()
fmt.Println(h, p, err)
}

// Output:
// <nil>
25 changes: 24 additions & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
// nil: Set node value to zero of return type
f := sc.def
var typ *itype
if typ, err = nodeType(interp, sc, f.child[2].child[1].child[i].lastChild()); err != nil {
if typ, err = nodeType(interp, sc, f.child[2].child[1].fieldType(i)); err != nil {
return
}
if typ.cat == funcT {
Expand Down Expand Up @@ -1643,6 +1643,29 @@ func (n *node) isNatural() bool {
return false
}

// fieldType returns the nth parameter field node (type) of a fieldList node
func (n *node) fieldType(m int) *node {
k := 0
l := len(n.child)
for i := 0; i < l; i++ {
cl := len(n.child[i].child)
if cl < 2 {
if k == m {
return n.child[i].lastChild()
}
k++
continue
}
for j := 0; j < cl-1; j++ {
if k == m {
return n.child[i].lastChild()
}
k++
}
}
return nil
}

// lastChild returns the last child of a node
func (n *node) lastChild() *node { return n.child[len(n.child)-1] }

Expand Down

0 comments on commit e1ac83f

Please sign in to comment.