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>
This commit is contained in:
Robert Griesemer 2020-01-30 20:13:02 -08:00 committed by Ian Lance Taylor
parent b7689f5aa3
commit 6e592c2b6d
4 changed files with 12 additions and 13 deletions

View file

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

View file

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

View file

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

View file

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