Standard library / go/types

go/types.Named.SetTypeParams()

Sets the declared type parameters on an uninstantiated named type. Expected stdout: '1 0\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Named) SetTypeParams(tparams []*TypeParam)

Parameters & Attributes

NameTypeDescription
tparams[]*TypeParamInput to the operation as described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  v := types.NewNamed(types.NewTypeName(0, nil, "N", nil), types.Typ[types.Int], nil)  p := types.NewTypeParam(types.NewTypeName(0, nil, "T", nil), types.Universe.Lookup("any").Type())  v.SetTypeParams([]*types.TypeParam{p})  fmt.Println(v.TypeParams().Len(), p.Index())}
Go Reference