diff options
author | Robert Griesemer <gri@golang.org> | 2020-01-30 20:13:02 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-01-31 14:46:05 +0000 |
commit | 6e592c2b6d3d32f0eb1211a3795e852627c7a086 (patch) | |
tree | 2c2b17e9bec1f2e87f9738af1e23035485c8ad08 | |
parent | b7689f5aa38b41c8fbd75d64aa463b898c81fca5 (diff) | |
download | go-6e592c2b6d3d32f0eb1211a3795e852627c7a086.tar.gz go-6e592c2b6d3d32f0eb1211a3795e852627c7a086.zip |
go/types: unexport Checker.LookupFieldOrMethod
Implementation changes in go/types for #6977 required that internal
LookupFieldOrMethod calls had access to the current *Checker. In
order to make quick progress, I added a *Checker receiver to the
function LookupFieldOrMethod (thus making it a method), and added
a new function LookupFieldOrMethod. The plan was always to rename
that function (Checker.LookupFieldOrMethod) such that it wouldn't
be exported; with the obvious name being Checker.lookupFieldOrMethod.
But that name was already in use which is why I postponed the rename.
Eventually I forgot to clean it up. This CL fixes that with the
following renames:
Checker.lookupFieldOrMethod => Checker.rawLookupFieldOrMethod
Checker.LookupFieldOrMethod => Checker.lookupFieldOrMethod
Updates #6977.
Fixes #36916.
Change-Id: Icfafd0de9a19841ba5bd87142730fe7323204491
Reviewed-on: https://go-review.googlesource.com/c/go/+/217134
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r-- | api/go1.14.txt | 1 | ||||
-rw-r--r-- | src/go/types/builtins.go | 2 | ||||
-rw-r--r-- | src/go/types/call.go | 2 | ||||
-rw-r--r-- | src/go/types/lookup.go | 20 |
4 files changed, 12 insertions, 13 deletions
diff --git a/api/go1.14.txt b/api/go1.14.txt index af962ec0ab..3af0fee3b4 100644 --- a/api/go1.14.txt +++ b/api/go1.14.txt @@ -150,7 +150,6 @@ pkg go/doc, type Example struct, Suffix string pkg go/doc, type Func struct, Examples []*Example pkg go/doc, type Package struct, Examples []*Example pkg go/doc, type Type struct, Examples []*Example -pkg go/types, method (*Checker) LookupFieldOrMethod(Type, bool, *Package, string) (Object, []int, bool) pkg hash/maphash, func MakeSeed() Seed pkg hash/maphash, method (*Hash) BlockSize() int pkg hash/maphash, method (*Hash) Reset() diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index af374b70c6..3756303dfb 100644 --- a/src/go/types/builtins.go +++ b/src/go/types/builtins.go @@ -559,7 +559,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b base := derefStructPtr(x.typ) sel := selx.Sel.Name - obj, index, indirect := check.LookupFieldOrMethod(base, false, check.pkg, sel) + obj, index, indirect := check.lookupFieldOrMethod(base, false, check.pkg, sel) switch obj.(type) { case nil: check.invalidArg(x.pos(), "%s has no single field %s", base, sel) diff --git a/src/go/types/call.go b/src/go/types/call.go index 31f9372644..689ef8744c 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -370,7 +370,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { goto Error } - obj, index, indirect = check.LookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel) + obj, index, indirect = check.lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel) if obj == nil { switch { case index != nil: diff --git a/src/go/types/lookup.go b/src/go/types/lookup.go index 648e100060..342c8baab2 100644 --- a/src/go/types/lookup.go +++ b/src/go/types/lookup.go @@ -33,19 +33,19 @@ package types // the method's formal receiver base type, nor was the receiver addressable. // func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) { - return (*Checker)(nil).LookupFieldOrMethod(T, addressable, pkg, name) + return (*Checker)(nil).lookupFieldOrMethod(T, addressable, pkg, name) } -// Internal use of Checker.LookupFieldOrMethod: If the obj result is a method +// Internal use of Checker.lookupFieldOrMethod: If the obj result is a method // associated with a concrete (non-interface) type, the method's signature // may not be fully set up. Call Checker.objDecl(obj, nil) before accessing // the method's type. // TODO(gri) Now that we provide the *Checker, we can probably remove this -// caveat by calling Checker.objDecl from LookupFieldOrMethod. Investigate. +// caveat by calling Checker.objDecl from lookupFieldOrMethod. Investigate. -// LookupFieldOrMethod is like the external version but completes interfaces +// lookupFieldOrMethod is like the external version but completes interfaces // as necessary. -func (check *Checker) LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) { +func (check *Checker) lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) { // Methods cannot be associated to a named pointer type // (spec: "The type denoted by T is called the receiver base type; // it must not be a pointer or interface type and it must be declared @@ -55,7 +55,7 @@ func (check *Checker) LookupFieldOrMethod(T Type, addressable bool, pkg *Package // not have found it for T (see also issue 8590). if t, _ := T.(*Named); t != nil { if p, _ := t.underlying.(*Pointer); p != nil { - obj, index, indirect = check.lookupFieldOrMethod(p, false, pkg, name) + obj, index, indirect = check.rawLookupFieldOrMethod(p, false, pkg, name) if _, ok := obj.(*Func); ok { return nil, nil, false } @@ -63,7 +63,7 @@ func (check *Checker) LookupFieldOrMethod(T Type, addressable bool, pkg *Package } } - return check.lookupFieldOrMethod(T, addressable, pkg, name) + return check.rawLookupFieldOrMethod(T, addressable, pkg, name) } // TODO(gri) The named type consolidation and seen maps below must be @@ -71,8 +71,8 @@ func (check *Checker) LookupFieldOrMethod(T Type, addressable bool, pkg *Package // types always have only one representation (even when imported // indirectly via different packages.) -// lookupFieldOrMethod should only be called by LookupFieldOrMethod and missingMethod. -func (check *Checker) lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) { +// rawLookupFieldOrMethod should only be called by lookupFieldOrMethod and missingMethod. +func (check *Checker) rawLookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) { // WARNING: The code in this function is extremely subtle - do not modify casually! // This function and NewMethodSet should be kept in sync. @@ -297,7 +297,7 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method * // A concrete type implements T if it implements all methods of T. for _, m := range T.allMethods { - obj, _, _ := check.lookupFieldOrMethod(V, false, m.pkg, m.name) + obj, _, _ := check.rawLookupFieldOrMethod(V, false, m.pkg, m.name) // we must have a method (not a field of matching function type) f, _ := obj.(*Func) |