aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/types2/check.go3
-rw-r--r--src/go/types/check.go6
-rw-r--r--src/go/types/eval.go2
3 files changed, 6 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/types2/check.go b/src/cmd/compile/internal/types2/check.go
index 9e77ba51df..52ff2ea032 100644
--- a/src/cmd/compile/internal/types2/check.go
+++ b/src/cmd/compile/internal/types2/check.go
@@ -57,7 +57,6 @@ type environment struct {
decl *declInfo // package-level declaration whose init expression/function body is checked
scope *Scope // top-most scope for lookups
version goVersion // current accepted language version; changes across files
- pos syntax.Pos // if valid, identifiers are looked up as if at position pos (used by Eval)
iota constant.Value // value of iota in a constant declaration; nil otherwise
errpos syntax.Pos // if valid, identifier position of a constant with inherited initializer
inTParamList bool // set if inside a type parameter list
@@ -77,7 +76,7 @@ type environment struct {
// whose parent is the scope of the package that exported them.
func (env *environment) lookupScope(name string) (*Scope, Object) {
for s := env.scope; s != nil; s = s.parent {
- if obj := s.Lookup(name); obj != nil && (!env.pos.IsKnown() || cmpPos(obj.scopePos(), env.pos) <= 0) {
+ if obj := s.Lookup(name); obj != nil {
return s, obj
}
}
diff --git a/src/go/types/check.go b/src/go/types/check.go
index 5f3c5c6792..8c68a1aafd 100644
--- a/src/go/types/check.go
+++ b/src/go/types/check.go
@@ -73,7 +73,6 @@ type environment struct {
decl *declInfo // package-level declaration whose init expression/function body is checked
scope *Scope // top-most scope for lookups
version goVersion // current accepted language version; changes across files
- pos token.Pos // if valid, identifiers are looked up as if at position pos (used by Eval)
iota constant.Value // value of iota in a constant declaration; nil otherwise
errpos positioner // if set, identifier position of a constant with inherited initializer
inTParamList bool // set if inside a type parameter list
@@ -81,6 +80,9 @@ type environment struct {
isPanic map[*ast.CallExpr]bool // set of panic call expressions (used for termination check)
hasLabel bool // set if a function makes use of labels (only ~1% of functions); unused outside functions
hasCallOrRecv bool // set if an expression contains a function call or channel receive operation
+
+ // go/types only
+ exprPos token.Pos // if valid, identifiers are looked up as if at position pos (used by CheckExpr, Eval)
}
// lookupScope looks up name in the current environment and if an object
@@ -93,7 +95,7 @@ type environment struct {
// whose parent is the scope of the package that exported them.
func (env *environment) lookupScope(name string) (*Scope, Object) {
for s := env.scope; s != nil; s = s.parent {
- if obj := s.Lookup(name); obj != nil && (!env.pos.IsValid() || cmpPos(obj.scopePos(), env.pos) <= 0) {
+ if obj := s.Lookup(name); obj != nil && (!env.exprPos.IsValid() || cmpPos(obj.scopePos(), env.exprPos) <= 0) {
return s, obj
}
}
diff --git a/src/go/types/eval.go b/src/go/types/eval.go
index 36184415f1..b7cde951b6 100644
--- a/src/go/types/eval.go
+++ b/src/go/types/eval.go
@@ -86,7 +86,7 @@ func CheckExpr(fset *token.FileSet, pkg *Package, pos token.Pos, expr ast.Expr,
// initialize checker
check := NewChecker(nil, fset, pkg, info)
check.scope = scope
- check.pos = pos
+ check.exprPos = pos
defer check.handleBailout(&err)
// evaluate node