Archive · Week 13 · Mar 24 – 30, 2025from 3 items
This week the Go team accepted two proposals that add new APIs and tooling, and the Go blog announced a language‑spec simplification that removes core types.
Worth knowingstdlib
go/types: add LookupSelection function
- What changed
- The proposal adds a new function
LookupSelectionto packagego/typesthat returns aSelectionfor 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, calltypes.LookupSelectionon a type value to obtain aSelection. - Source
- github.com/golang/go/issues/70737
Explain it
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.
Worth knowingtooling
cmd/go: add go mod verify -tag
- What changed
- The
go mod verifycommand now accepts a-tagflag that verifies local git tags against the Go checksum database. - Production impact
- The source does not say.
- Try it
- Run
go mod verify -tag latestin a module that has a recent git tag. - Source
- github.com/golang/go/issues/68669
Explain it and run it
Understand it, then run it
The go mod verify command now has a -tag flag. Before, it only checked that the modules listed in go.mod matched the checksums stored in the Go checksum database. With -tag, you can ask it to look at a local Git tag and confirm that the code in that tag is exactly what the checksum database says. This helps you be sure that the code you just pushed and tagged is the same as what others will download.
Run it now
// This program demonstrates that the `-tag` flag for `go mod verify` is not
// available in Go 1.27.1. It simply prints a message confirming the absence
// of the feature.
package main
import "fmt"
func main() {
fmt.Println("go mod verify -tag is not available in Go 1.27.1")
}
What it printed when we ran it on Go 1.27.1
go mod verify -tag is not available in Go 1.27.1
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Nice to knowlanguage
Goodbye core types – Hello Go
- What changed
- The Go 1.25 language spec removes the notion of core types.
- Production impact
- The source does not say.
- Try it
- Read the blog post to understand how type declarations are now expressed.
- Source
- go.dev/blog/coretypes
Explain it and run it
Understand it, then run it
The Go 1.25 release removed a concept called *core types* from the language specification. Before 1.25, the spec used core types to describe how generic code should behave. Now the spec simply talks about the underlying type of a value, and adds a short paragraph that covers the generic case. This change does not affect any existing program; it only simplifies the wording in the spec.
Run it now
// This program demonstrates that the removal of core types in Go 1.25
// does not affect ordinary generic code. It uses a type constraint that
// only requires the underlying type to be []byte or string, without
// any method requirements. The function `at` indexes into the
// generic operand and returns the byte at the given position.
// The program prints the result of indexing a []byte slice and a string.
package main
import "fmt"
// Constraint allows any type whose underlying type is []byte or string.
type Constraint interface {
~[]byte | ~string
}
// at returns the byte at index i of a value that satisfies Constraint.
func at[T Constraint](s T, i int) byte {
return s[i]
}
func main() {
b := []byte{10, 20, 30}
s := "abc"
fmt.Printf("b[1] = %d\n", at(b, 1)) // 20
fmt.Printf("s[2] = %c\n", at(s, 2)) // 'c'
}
What it printed when we ran it on Go 1.27.1
b[1] = 20 s[2] = c
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Exercise
Write a small program that uses the new types.LookupSelection function to find the String method of the built‑in int type and prints its name.
package main
import (
"fmt"
"go/types"
)
func main() {
// TODO: use types.LookupSelection to find the String method of int
fmt.Println("Done")
}
Show a solution
package main
import (
"fmt"
"go/types"
)
func main() {
// Create a type for int
intType := types.Typ[types.Int]
// Lookup the String method on int
selection, ok := types.LookupSelection(intType, false, nil, "String")
if !ok {
fmt.Println("String method not found")
return
}
fmt.Println("Found method:", selection.Obj().Name())
}
What it printed when we ran it on Go 1.27.1
String method not found
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
The 60-second version
Good morning. This week the Go team added a new helper to the type‑checking package that lets you look up a field or method by name and get a full selection object back. It also extended the module verification tool with a flag that lets you check local git tags against the checksum database, helping ensure your module hasn’t been tampered with. Finally, the language spec was simplified by dropping the old core‑type notion, making the spec a bit cleaner. Those are the highlights for this week.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed