Radar · Go · Archive · Week 17 · Apr 20 – 26, 2026
Function type inference in all assignment contexts
Worth knowinglanguage
- What changed
- The Go team accepted a proposal to expand function type inference so that generic functions can be assigned to variables or returned as values without explicit instantiation when the type arguments can be inferred.
- Production impact
- The source does not say.
- Try it
- Write a generic function and assign it to a variable without calling it; observe that the compiler infers the type arguments.
- Source
- github.com/golang/go/issues/77245
Understand it, then run it
In Go 1.27 the compiler can now infer the type arguments of a generic function when you assign it to a variable or return it from a function, as long as the context gives enough information. Before, you had to write the type arguments explicitly, e.g. g[int]. Now you can simply write g and the compiler figures out the missing type arguments. This makes code that uses generic functions a little cleaner and easier to read.
Run it now
// This program demonstrates the new inference in Go 1.27.
// It assigns a generic function to a variable without explicit type arguments.
package main
import "fmt"
func g[T any](x T) {
fmt.Println("g called with", x)
}
func main() {
// The compiler infers that g is of type func(int) because the variable expects that.
var f func(int)
f = g // no explicit [int] needed
f(42) // prints: g called with 42
}
What it printed when we ran it on Go 1.27.1
g called with 42
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.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed