Skip to content

Commit f7fb515

Browse files
committed
internal/analysisinternal: check for interface recievers
typesinternal.ReceiverNamed(R) may return nil on a interface method receiver R. Document this, and update analysisinternal.IsMethodNamed to allow for this this. Fixes golang/go#70399 Change-Id: I4f0542f2f9495cc373ad2d772736152b29dcc254 Cq-Include-Trybots: luci.golang.try:x_tools-gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/tools/+/641177 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent b4e093e commit f7fb515

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

internal/analysisinternal/analysis.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ func IsMethodNamed(obj types.Object, pkgPath string, typeName string, names ...s
336336
if fn, ok := obj.(*types.Func); ok {
337337
if recv := fn.Type().(*types.Signature).Recv(); recv != nil {
338338
_, T := typesinternal.ReceiverNamed(recv)
339-
return IsTypeNamed(T, pkgPath, typeName) &&
339+
return T != nil &&
340+
IsTypeNamed(T, pkgPath, typeName) &&
340341
slices.Contains(names, fn.Name())
341342
}
342343
}

internal/typesinternal/recv.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
// type of recv, which may be of the form N or *N, or aliases thereof.
1313
// It also reports whether a Pointer was present.
1414
//
15-
// The named result may be nil in ill-typed code.
15+
// The named result may be nil if recv is from a method on an
16+
// anonymous interface or struct types or in ill-typed code.
1617
func ReceiverNamed(recv *types.Var) (isPtr bool, named *types.Named) {
1718
t := recv.Type()
1819
if ptr, ok := types.Unalias(t).(*types.Pointer); ok {

0 commit comments

Comments
 (0)