@@ -10,6 +10,7 @@ import (
10
10
"reflect"
11
11
12
12
"golang.org/x/tools/internal/aliases"
13
+ "golang.org/x/tools/internal/typesinternal"
13
14
)
14
15
15
16
func (d * differ ) checkCompatible (otn * types.TypeName , old , new types.Type ) {
@@ -305,7 +306,8 @@ func (d *differ) checkMethodSet(otn *types.TypeName, oldt, newt types.Type, addc
305
306
// T and one for the embedded type U. We want both messages to appear,
306
307
// but the messageSet dedup logic will allow only one message for a given
307
308
// object. So use the part string to distinguish them.
308
- if receiverNamedType (oldMethod ).Obj () != otn {
309
+ recv := oldMethod .Type ().(* types.Signature ).Recv ()
310
+ if _ , named := typesinternal .ReceiverNamed (recv ); named .Obj () != otn {
309
311
part = fmt .Sprintf (", method set of %s" , msname )
310
312
}
311
313
d .incompatible (oldMethod , part , "removed" )
@@ -336,34 +338,19 @@ func (d *differ) checkMethodSet(otn *types.TypeName, oldt, newt types.Type, addc
336
338
}
337
339
338
340
// exportedMethods collects all the exported methods of type's method set.
339
- func exportedMethods (t types.Type ) map [string ]types.Object {
340
- m := map [string ]types.Object {}
341
+ func exportedMethods (t types.Type ) map [string ]* types.Func {
342
+ m := make ( map [string ]* types.Func )
341
343
ms := types .NewMethodSet (t )
342
344
for i := 0 ; i < ms .Len (); i ++ {
343
- obj := ms .At (i ).Obj ()
345
+ obj := ms .At (i ).Obj ().( * types. Func )
344
346
if obj .Exported () {
345
347
m [obj .Name ()] = obj
346
348
}
347
349
}
348
350
return m
349
351
}
350
352
351
- func receiverType (method types.Object ) types.Type {
352
- return method .Type ().(* types.Signature ).Recv ().Type ()
353
- }
354
-
355
- func receiverNamedType (method types.Object ) * types.Named {
356
- switch t := aliases .Unalias (receiverType (method )).(type ) {
357
- case * types.Pointer :
358
- return aliases .Unalias (t .Elem ()).(* types.Named )
359
- case * types.Named :
360
- return t
361
- default :
362
- panic ("unreachable" )
363
- }
364
- }
365
-
366
- func hasPointerReceiver (method types.Object ) bool {
367
- _ , ok := aliases .Unalias (receiverType (method )).(* types.Pointer )
368
- return ok
353
+ func hasPointerReceiver (method * types.Func ) bool {
354
+ isptr , _ := typesinternal .ReceiverNamed (method .Type ().(* types.Signature ).Recv ())
355
+ return isptr
369
356
}
0 commit comments