Skip to content

proposal: go/types: add Func.RecvBase method #81715

Open

Description

@adonovan

@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() (isPtr bool, 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

  1. added this to the Proposal milestone on Sep 23, 2026
  2. gopherbot commented on Sep 24, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/837525 mentions this issue: internal/typesinternal: RecvBase, replaces ReceiverNamed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions