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>
This commit is contained in:
Robert Griesemer 2024-09-27 11:03:58 -07:00 committed by Gopher Robot
parent 6ad3933e28
commit 676d427f77
3 changed files with 6 additions and 5 deletions

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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