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 23 · Jun 1 – 7, 2026

go/types: NewTypeParamList and NewTypeList constructors

Nice to knowstdlib

What changed
The Go team added two constructors to go/types: NewTypeParamList(tparams ...*TypeParam) *TypeParamList and NewTypeList(types ...*Type) *TypeList. These allow creating new type‑parameter and type lists programmatically.
Production impact
The source does not say.
Try it
Write a small program that uses go/types to create a TypeParamList from a slice of *TypeParam.
Source
github.com/golang/go/issues/79603

Understand it, then run it

Run it now

Todaygo
// This program demonstrates how to create a *types.TypeParamList in Go 1.27.1,
// where the NewTypeParamList constructor is not yet available. It uses an
// unsafe cast from a slice of *types.TypeParam to *types.TypeParamList,
// which is the workaround that existed before the proposed constructor
// shipped in Go 1.28.
//
// The program defines two dummy type parameters, builds a slice, casts it,
// and prints the number of parameters in the resulting list.
package main

import (
	"fmt"
	"go/types"
	"unsafe"
)

func main() {
	// Create two dummy type parameters. In practice these would come from
	// parsing or type-checking code, but here we fabricate them with
	// minimal information.
	tp1 := &types.TypeParam{
		// The fields of TypeParam are unexported, so we cannot set them
		// directly. We only need the pointer to satisfy the slice.
	}
	tp2 := &types.TypeParam{}

	// Build a slice of *types.TypeParam.
	tps := []*types.TypeParam{tp1, tp2}

	// Convert the slice to a *types.TypeParamList via an unsafe cast.
	// This relies on the internal layout of TypeParamList matching a
	// slice header, which is true in the current implementation.
	tpl := (*types.TypeParamList)(unsafe.Pointer(&tps))

	// Print the length of the constructed list.
	fmt.Printf("TypeParamList contains %d parameters\n", tpl.Len())
}

What it printed when we ran it on Go 1.27.1

TypeParamList contains 2 parameters

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