This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

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