@@ -152,16 +152,9 @@ func (l *Labeler) ScopedObjectID(object types.Object, getTypeLabel func() Label)
152
152
panic (fmt .Sprintf ("Object has no scope: %v :: %v.\n " , object ,
153
153
l .tw .Package .Fset .Position (object .Pos ())))
154
154
} else {
155
- // associate method receiver objects to special keys, because those can be
156
- // referenced from other files via their method
157
- meth := findMethodWithGivenReceiver (object .Type (), object )
158
- if meth == nil {
159
- if pointerType , ok := object .Type ().(* types.Pointer ); ok {
160
- meth = findMethodWithGivenReceiver (pointerType .Elem (), object )
161
- }
162
- }
163
-
164
- if meth != nil {
155
+ if meth := findMethodWithGivenReceiver (object ); meth != nil {
156
+ // associate method receiver objects to special keys, because those can be
157
+ // referenced from other files via their method
165
158
methlbl , _ := l .MethodID (meth , getTypeLabel ())
166
159
label , _ = l .ReceiverObjectID (object , methlbl )
167
160
} else {
@@ -174,7 +167,20 @@ func (l *Labeler) ScopedObjectID(object types.Object, getTypeLabel func() Label)
174
167
return label , exists
175
168
}
176
169
177
- func findMethodWithGivenReceiver (tp types.Type , object types.Object ) * types.Func {
170
+ // findMethodWithGivenReceiver finds a method with `object` as its receiver, if one exists
171
+ func findMethodWithGivenReceiver (object types.Object ) * types.Func {
172
+ meth := findMethodOnTypeWithGivenReceiver (object .Type (), object )
173
+ if meth != nil {
174
+ return meth
175
+ }
176
+ if pointerType , ok := object .Type ().(* types.Pointer ); ok {
177
+ meth = findMethodOnTypeWithGivenReceiver (pointerType .Elem (), object )
178
+ }
179
+ return meth
180
+ }
181
+
182
+ // findMethodWithGivenReceiver finds a method on type `tp` with `object` as its receiver, if one exists
183
+ func findMethodOnTypeWithGivenReceiver (tp types.Type , object types.Object ) * types.Func {
178
184
if namedType , ok := tp .(* types.Named ); ok {
179
185
for i := 0 ; i < namedType .NumMethods (); i ++ {
180
186
meth := namedType .Method (i )
0 commit comments