aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2024-09-27 11:03:58 -0700
committerGopher Robot <gobot@golang.org>2024-09-27 19:24:18 +0000
commit676d427f77ea255fa6e4cdebf0fb348a27575855 (patch)
tree7d39debe11688fa29119777814802cddfe1d2707 /src
parent6ad3933e285b036137a339f598f00a21578fcbfb (diff)
downloadgo-676d427f77ea255fa6e4cdebf0fb348a27575855.tar.xz
go/types, types2: remove Checker.pos from types2 code - not needed anymore
In go/types, move field down in environment struct, rename it to exprPos, and document use. Updates #69673. Change-Id: I355af1237f8cd731ad9706e6a5fce34b314978cc Reviewed-on: https://go-review.googlesource.com/c/go/+/616316 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
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