Skip to content

Commit 6e592c2

Browse files
griesemerianlancetaylor
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b7689f5 commit 6e592c2

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

api/go1.14.txt

-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ pkg go/doc, type Example struct, Suffix string
150150
pkg go/doc, type Func struct, Examples []*Example
151151
pkg go/doc, type Package struct, Examples []*Example
152152
pkg go/doc, type Type struct, Examples []*Example
153-
pkg go/types, method (*Checker) LookupFieldOrMethod(Type, bool, *Package, string) (Object, []int, bool)
154153
pkg hash/maphash, func MakeSeed() Seed
155154
pkg hash/maphash, method (*Hash) BlockSize() int
156155
pkg hash/maphash, method (*Hash) Reset()

src/go/types/builtins.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
559559

560560
base := derefStructPtr(x.typ)
561561
sel := selx.Sel.Name
562-
obj, index, indirect := check.LookupFieldOrMethod(base, false, check.pkg, sel)
562+
obj, index, indirect := check.lookupFieldOrMethod(base, false, check.pkg, sel)
563563
switch obj.(type) {
564564
case nil:
565565
check.invalidArg(x.pos(), "%s has no single field %s", base, sel)

src/go/types/call.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
370370
goto Error
371371
}
372372

373-
obj, index, indirect = check.LookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel)
373+
obj, index, indirect = check.lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel)
374374
if obj == nil {
375375
switch {
376376
case index != nil:

src/go/types/lookup.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ package types
3333
// the method's formal receiver base type, nor was the receiver addressable.
3434
//
3535
func LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) {
36-
return (*Checker)(nil).LookupFieldOrMethod(T, addressable, pkg, name)
36+
return (*Checker)(nil).lookupFieldOrMethod(T, addressable, pkg, name)
3737
}
3838

39-
// Internal use of Checker.LookupFieldOrMethod: If the obj result is a method
39+
// Internal use of Checker.lookupFieldOrMethod: If the obj result is a method
4040
// associated with a concrete (non-interface) type, the method's signature
4141
// may not be fully set up. Call Checker.objDecl(obj, nil) before accessing
4242
// the method's type.
4343
// TODO(gri) Now that we provide the *Checker, we can probably remove this
44-
// caveat by calling Checker.objDecl from LookupFieldOrMethod. Investigate.
44+
// caveat by calling Checker.objDecl from lookupFieldOrMethod. Investigate.
4545

46-
// LookupFieldOrMethod is like the external version but completes interfaces
46+
// lookupFieldOrMethod is like the external version but completes interfaces
4747
// as necessary.
48-
func (check *Checker) LookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) {
48+
func (check *Checker) lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) {
4949
// Methods cannot be associated to a named pointer type
5050
// (spec: "The type denoted by T is called the receiver base type;
5151
// it must not be a pointer or interface type and it must be declared
@@ -55,24 +55,24 @@ func (check *Checker) LookupFieldOrMethod(T Type, addressable bool, pkg *Package
5555
// not have found it for T (see also issue 8590).
5656
if t, _ := T.(*Named); t != nil {
5757
if p, _ := t.underlying.(*Pointer); p != nil {
58-
obj, index, indirect = check.lookupFieldOrMethod(p, false, pkg, name)
58+
obj, index, indirect = check.rawLookupFieldOrMethod(p, false, pkg, name)
5959
if _, ok := obj.(*Func); ok {
6060
return nil, nil, false
6161
}
6262
return
6363
}
6464
}
6565

66-
return check.lookupFieldOrMethod(T, addressable, pkg, name)
66+
return check.rawLookupFieldOrMethod(T, addressable, pkg, name)
6767
}
6868

6969
// TODO(gri) The named type consolidation and seen maps below must be
7070
// indexed by unique keys for a given type. Verify that named
7171
// types always have only one representation (even when imported
7272
// indirectly via different packages.)
7373

74-
// lookupFieldOrMethod should only be called by LookupFieldOrMethod and missingMethod.
75-
func (check *Checker) lookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) {
74+
// rawLookupFieldOrMethod should only be called by lookupFieldOrMethod and missingMethod.
75+
func (check *Checker) rawLookupFieldOrMethod(T Type, addressable bool, pkg *Package, name string) (obj Object, index []int, indirect bool) {
7676
// WARNING: The code in this function is extremely subtle - do not modify casually!
7777
// This function and NewMethodSet should be kept in sync.
7878

@@ -297,7 +297,7 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method *
297297

298298
// A concrete type implements T if it implements all methods of T.
299299
for _, m := range T.allMethods {
300-
obj, _, _ := check.lookupFieldOrMethod(V, false, m.pkg, m.name)
300+
obj, _, _ := check.rawLookupFieldOrMethod(V, false, m.pkg, m.name)
301301

302302
// we must have a method (not a field of matching function type)
303303
f, _ := obj.(*Func)

0 commit comments

Comments
 (0)