From 6e592c2b6d3d32f0eb1211a3795e852627c7a086 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 30 Jan 2020 20:13:02 -0800 Subject: [PATCH] go/types: unexport Checker.LookupFieldOrMethod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí Reviewed-by: Ian Lance Taylor --- api/go1.14.txt | 1 - src/go/types/builtins.go | 2 +- src/go/types/call.go | 2 +- 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 af962ec0abfcfd..3af0fee3b4cad9 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 af374b70c6973e..3756303dfbca93 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 31f93726446d41..689ef8744c446e 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 648e100060b61e..342c8baab24f26 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)