Radar · Go · Archive · Week 49 · Dec 1 – 7, 2025
Alias type parameter restriction relaxed
Worth knowinglanguage
- What changed
- The Go spec now allows a type parameter to appear on the right‑hand side of an alias type declaration, but only when the type parameter is declared in the same declaration.
- Production impact
- The source does not say.
- Try it
- Compile a package that declares
type T[T any] = []Tand observe that it is now accepted. - Source
- github.com/golang/go/issues/75885
Understand it, then run it
Run it now
// This program demonstrates the relaxed alias rule.
// It defines a generic alias that uses a type parameter declared in the same statement.
package main
import "fmt"
// Generic alias: MySlice[T] is an alias for []T.
// The type parameter T is declared in the same line, which is now allowed.
type MySlice[T any] = []T
func main() {
// Create a MySlice[int] and populate it.
var nums MySlice[int] = MySlice[int]{1, 2, 3}
fmt.Println(nums) // Output: [1 2 3]
}
What it printed when we ran it on Go 1.27.1
[1 2 3]
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