Sign in

Radar · Go · Archive · Week 13 · Mar 24 – 30, 2025

go/types: add LookupSelection function

Worth knowingstdlib

What changed
The proposal adds a new function LookupSelection to package go/types that returns a Selection for a field or method identified by a package and name.
Production impact
The source does not say.
Try it
In a program that imports go/types, call types.LookupSelection on a type value to obtain a Selection.
Source
github.com/golang/go/issues/70737

Understand it, then run it

The Go type system can tell you which field or method a value has. Before the change, the only way to get that information was through a helper called LookupFieldOrMethod. That helper returns three separate pieces of data: the object, the indices that locate it, and whether the value is indirect. It does not give you a single object that represents the whole selection. The new LookupSelection function will return a Selection value that bundles all that information together, making it easier to work with selections in code.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed