Fix handling of function types

Fix a bug where type was skipped if several arguments where factorized
on the same type.
This commit is contained in:
Marc Vertes
2018-11-19 14:37:24 +01:00
parent 503b1d9119
commit e21513faf8
2 changed files with 15 additions and 2 deletions

View File

@@ -462,6 +462,7 @@ func call(n *Node) {
if variadic >= 0 && i >= variadic {
argType = n.child[0].typ.arg[variadic].TypeOf()
} else {
log.Println(n.index, i, n.child[0].typ.node.index)
argType = n.child[0].typ.arg[i].TypeOf()
}
if argType != nil && argType.Kind() != reflect.Interface {

View File

@@ -188,15 +188,27 @@ func nodeType(interp *Interpreter, scope *Scope, n *Node) *Type {
case FuncType:
t.cat = FuncT
// Handle input parameters
for _, arg := range n.child[0].child {
typ := nodeType(interp, scope, arg.child[len(arg.child)-1])
cl := len(arg.child) - 1
typ := nodeType(interp, scope, arg.child[cl])
t.arg = append(t.arg, typ)
for i := 1; i < cl; i++ {
// Several arguments may be factorized on the same field type
t.arg = append(t.arg, typ)
}
t.incomplete = t.incomplete || typ.incomplete
}
if len(n.child) == 2 {
// Handle returned values
for _, ret := range n.child[1].child {
typ := nodeType(interp, scope, ret.child[len(ret.child)-1])
cl := len(ret.child) - 1
typ := nodeType(interp, scope, ret.child[cl])
t.ret = append(t.ret, typ)
for i := 1; i < cl; i++ {
// Several arguments may be factorized on the same field type
t.ret = append(t.ret, typ)
}
t.incomplete = t.incomplete || typ.incomplete
}
}