if tag == 'G' {
tparams = r.tparamList()
}
- sig := r.signature(nil)
- sig.SetTypeParams(tparams)
+ sig := r.signature(nil, nil, tparams)
r.declare(types.NewFunc(pos, r.currPkg, name, sig))
case 'T', 'U':
mpos := r.pos()
mname := r.ident()
recv := r.param()
- msig := r.signature(recv)
// If the receiver has any targs, set those as the
// rparams of the method (since those are the
// typeparams being used in the method sig/body).
- targs := baseType(msig.Recv().Type()).TypeArgs()
+ targs := baseType(recv.Type()).TypeArgs()
+ var rparams []*types.TypeParam
if targs.Len() > 0 {
- rparams := make([]*types.TypeParam, targs.Len())
+ rparams = make([]*types.TypeParam, targs.Len())
for i := range rparams {
rparams[i], _ = targs.At(i).(*types.TypeParam)
}
- msig.SetRecvTypeParams(rparams)
}
+ msig := r.signature(recv, rparams, nil)
named.AddMethod(types.NewFunc(mpos, r.currPkg, mname, msig))
}
return types.NewMap(r.typ(), r.typ())
case signatureType:
r.currPkg = r.pkg()
- return r.signature(nil)
+ return r.signature(nil, nil, nil)
case structType:
r.currPkg = r.pkg()
recv = types.NewVar(token.NoPos, r.currPkg, "", base)
}
- msig := r.signature(recv)
+ msig := r.signature(recv, nil, nil)
methods[i] = types.NewFunc(mpos, r.currPkg, mname, msig)
}
return itag(r.uint64())
}
-func (r *importReader) signature(recv *types.Var) *types.Signature {
+func (r *importReader) signature(recv *types.Var, rparams, tparams []*types.TypeParam) *types.Signature {
params := r.paramList()
results := r.paramList()
variadic := params.Len() > 0 && r.bool()
- return types.NewSignature(recv, params, results, variadic)
+ return types.NewSignatureType(recv, rparams, tparams, params, results, variadic)
}
func (r *importReader) tparamList() []*types.TypeParam {
// and results, either of which may be nil. If variadic is set, the function
// is variadic, it must have at least one parameter, and the last parameter
// must be of unnamed slice type.
+//
+// Deprecated: Use NewSignatureType instead which allows for type parameters.
func NewSignature(recv *Var, params, results *Tuple, variadic bool) *Signature {
+ return NewSignatureType(recv, nil, nil, params, results, variadic)
+}
+
+// NewSignatureType creates a new function type for the given receiver,
+// receiver type parameters, type parameters, parameters, and results. If
+// variadic is set, params must hold at least one parameter and the last
+// parameter must be of unnamed slice type. If recv is non-nil, typeParams must
+// be empty. If recvTypeParams is non-empty, recv must be non-nil.
+func NewSignatureType(recv *Var, recvTypeParams, typeParams []*TypeParam, params, results *Tuple, variadic bool) *Signature {
if variadic {
n := params.Len()
if n == 0 {
panic("variadic parameter must be of unnamed slice type")
}
}
- return &Signature{recv: recv, params: params, results: results, variadic: variadic}
+ sig := &Signature{recv: recv, params: params, results: results, variadic: variadic}
+ if len(recvTypeParams) != 0 {
+ if recv == nil {
+ panic("function with receiver type parameters must have a receiver")
+ }
+ sig.rparams = bindTParams(recvTypeParams)
+ }
+ if len(typeParams) != 0 {
+ if recv != nil {
+ panic("function with type parameters cannot have a receiver")
+ }
+ sig.tparams = bindTParams(typeParams)
+ }
+ return sig
}
// Recv returns the receiver of signature s (if a method), or nil if a