fix: improving handling of functions returning interfaces

This commit is contained in:
Marc Vertes
2020-05-03 17:46:03 +02:00
committed by GitHub
parent 7d56fb067e
commit e4acba031d
7 changed files with 77 additions and 2 deletions

View File

@@ -253,10 +253,13 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
}
// If the node is to be assigned or returned, the node type is the destination type.
dt := t
if a := n.anc; a.kind == defineStmt && len(a.child) > a.nleft+a.nright {
switch a := n.anc; {
case a.kind == defineStmt && len(a.child) > a.nleft+a.nright:
if dt, err = nodeType(interp, sc, a.child[a.nleft]); err != nil {
return nil, err
}
case a.kind == returnStmt:
dt = sc.def.typ.ret[childPos(n)]
}
if isInterface(dt) {
dt.val = t