github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/types2/typeparam.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package types2 6 7 // A TypeParam represents a type parameter type. 8 type TypeParam struct { 9 check *Checker 10 id uint64 11 obj *TypeName 12 index int 13 bound Type 14 } 15 16 // NewTypeParam returns a new TypeParam. Type parameters may be set on a Named 17 // or Signature type by calling SetTypeParams. Setting a type parameter on more 18 // than one type will result in a panic. 19 // 20 // The constraint argument can be nil, and set later via SetConstraint. If the 21 // constraint is non-nil, it must be fully defined. 22 func NewTypeParam(obj *TypeName, constraint Type) *TypeParam 23 24 // Obj returns the type name for the type parameter t. 25 func (t *TypeParam) Obj() *TypeName 26 27 // Index returns the index of the type param within its param list, or -1 if 28 // the type parameter has not yet been bound to a type. 29 func (t *TypeParam) Index() int 30 31 // Constraint returns the type constraint specified for t. 32 func (t *TypeParam) Constraint() Type 33 34 // SetConstraint sets the type constraint for t. 35 // 36 // It must be called by users of NewTypeParam after the bound's underlying is 37 // fully defined, and before using the type parameter in any way other than to 38 // form other types. Once SetConstraint returns the receiver, t is safe for 39 // concurrent use. 40 func (t *TypeParam) SetConstraint(bound Type) 41 42 func (t *TypeParam) Underlying() Type 43 44 func (t *TypeParam) String() string