]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove Checker.pos from types2 code - not needed anymore
authorRobert Griesemer <gri@golang.org>
Fri, 27 Sep 2024 18:03:58 +0000 (11:03 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 27 Sep 2024 19:24:18 +0000 (19:24 +0000)
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>
src/cmd/compile/internal/types2/check.go
src/go/types/check.go
src/go/types/eval.go

index 9e77ba51df642f4b1179ad7a336f0f1e549d0e59..52ff2ea032fa92a474d26783025834797b5e5492 100644 (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
                }
        }
index 5f3c5c67922e67b66c8195974e4c3b558973eb05..8c68a1aafd10901d48e0cea0a7f807937905e9be 100644 (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
                }
        }
index 36184415f14cd286b4b03bc98ad07b437bac0548..b7cde951b6877d294333dd6e88e6479c8a37db88 100644 (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