interp: force root scope for binPkgT selector
This commit is contained in:
18
_test/selector-scope0.go
Normal file
18
_test/selector-scope0.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func test(time string, t time.Time) string {
|
||||
return time
|
||||
}
|
||||
|
||||
func main() {
|
||||
str := test("test", time.Now())
|
||||
fmt.Println(str)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// test
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user