Standard library / go/types

go/types.TypeParam.SetConstraint()

Sets a parameter constraint during type construction. Expected stdout: 'comparable\n'.

Formal Syntax & Structure

go syntaxgo
func (t *TypeParam) SetConstraint(bound Type)

Parameters & Attributes

NameTypeDescription
boundTypeType constraint.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  v := types.NewTypeParam(types.NewTypeName(0, nil, "T", nil), nil)  v.SetConstraint(types.Universe.Lookup("comparable").Type())  fmt.Println(v.Constraint())}
Go Reference