interp: force root scope for binPkgT selector

This commit is contained in:
mpl
2020-06-22 13:24:03 +02:00
committed by GitHub
parent a6c24a0d13
commit 7cfa264dbc
2 changed files with 41 additions and 1 deletions

View File

@@ -513,9 +513,31 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
case selectorExpr:
// Resolve the left part of selector, then lookup the right part on it
var lt *itype
if lt, err = nodeType(interp, sc, n.child[0]); err != nil {
// If we are in a list of func parameters, and we are a selector on a binPkgT, but
// one of the other parameters has the same name as the pkg name, in the list of
// symbols we would find the other parameter instead of the pkg because it comes
// first when looking up in the stack of scopes. So in that case we force the
// lookup directly in the root scope to shortcircuit that issue.
var localScope *scope
localScope = sc
if n.anc != nil && len(n.anc.child) > 1 && n.anc.child[1] == n &&
// This check is weaker than what we actually want to know, i.e. whether
// n.anc.child[0] is a variable, but it seems at this point in the run we have no
// way of knowing that yet (typ is nil, so there's no typ.cat yet).
n.anc.child[0].kind == identExpr {
for {
if localScope.level == 0 {
break
}
localScope = localScope.anc
}
}
if lt, err = nodeType(interp, localScope, n.child[0]); err != nil {
return nil, err
}
if lt.incomplete {
t.incomplete = true
break