You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@ianlancetaylor recently pointed out that third-party analyzer writers often need to copy a number of widely used helper internal functions from x/tools, and spurred me to think about which ones should be published.
One of the most commonly used go/types helpers (18 uses within x/tools) is RecvBase, which returns the "receiver base type" of a method. In other words, given N.M or (*N).M, it returns N, and additionally a boolean indicating the presence of the pointer.
We propose to add it to go/types as a method of *types.Func.
package types // "go/types"// RecvBase returns the receiver base type (if any) of the method fn,// and reports whether the receiver is a pointer to it.//// The spec says of a method declaration: the receiver's "type must be// a defined type T or a pointer to a defined type T, possibly followed// by a list of type parameter names [P1, P2, …] enclosed in square// brackets. T is called the receiver base type."//// The named result is nil if fn is not a method, or if its receiver// is an anonymous interface or struct type, as in interface{ f() }.func (fn*Func) RecvBase() (isPtrbool, named*types.Named)
BTW, the boolean result appears first to avoid misinterpretation as an ok bool, and because that's the natural
reading order in *Named.
Activity
gabyhelp commentedon Sep 23, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
internal/typesinternal: RecvBase, replaces ReceiverNamed
gopherbot commentedon Sep 24, 2026
Change https://go.dev/cl/837525 mentions this issue:
internal/typesinternal: RecvBase, replaces ReceiverNamed