From 1ff0554b5318d5a39e2b26a9c84330e6aa47b1c6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 23 Aug 2021 18:29:38 -0700 Subject: cmd/compile/internal/types2: use []*TypeParam rather than []*TypeName for type param lists This is a port of CL 343932 from go/types, with the necessary adjustments to the compiler. This change improves type safety slightly, avoids many internal type assertions, and simplifies some code paths. Change-Id: Ie9c4734814f49cd248927152d7b3264d3578428c Reviewed-on: https://go-review.googlesource.com/c/go/+/344614 Trust: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky Reviewed-by: Dan Scales --- src/cmd/compile/internal/types2/signature.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/cmd/compile/internal/types2/signature.go') diff --git a/src/cmd/compile/internal/types2/signature.go b/src/cmd/compile/internal/types2/signature.go index e319e65211..f1bf60ae8e 100644 --- a/src/cmd/compile/internal/types2/signature.go +++ b/src/cmd/compile/internal/types2/signature.go @@ -57,13 +57,13 @@ func (s *Signature) Recv() *Var { return s.recv } func (s *Signature) TParams() *TParamList { return s.tparams } // SetTParams sets the type parameters of signature s. -func (s *Signature) SetTParams(tparams []*TypeName) { s.tparams = bindTParams(tparams) } +func (s *Signature) SetTParams(tparams []*TypeParam) { s.tparams = bindTParams(tparams) } // RParams returns the receiver type parameters of signature s, or nil. func (s *Signature) RParams() *TParamList { return s.rparams } // SetRParams sets the receiver type params of signature s. -func (s *Signature) SetRParams(rparams []*TypeName) { s.rparams = bindTParams(rparams) } +func (s *Signature) SetRParams(rparams []*TypeParam) { s.rparams = bindTParams(rparams) } // Params returns the parameters of signature s, or nil. func (s *Signature) Params() *Tuple { return s.params } @@ -119,14 +119,14 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams [] // blank identifiers were found => use rewritten receiver type recvTyp = isubst(recvPar.Type, smap) } - rlist := make([]*TypeName, len(rparams)) + rlist := make([]*TypeParam, len(rparams)) for i, rparam := range rparams { rlist[i] = check.declareTypeParam(rparam) } sig.rparams = bindTParams(rlist) // determine receiver type to get its type parameters // and the respective type parameter bounds - var recvTParams []*TypeName + var recvTParams []*TypeParam if rname != nil { // recv should be a Named type (otherwise an error is reported elsewhere) // Also: Don't report an error via genericType since it will be reported @@ -142,19 +142,19 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams [] // We have a list of *TypeNames but we need a list of Types. list := make([]Type, sig.RParams().Len()) for i, t := range sig.RParams().list() { - list[i] = t.typ + list[i] = t } smap := makeSubstMap(recvTParams, list) - for i, tname := range sig.RParams().list() { - bound := recvTParams[i].typ.(*TypeParam).bound + for i, tpar := range sig.RParams().list() { + bound := recvTParams[i].bound // bound is (possibly) parameterized in the context of the // receiver type declaration. Substitute parameters for the // current context. // TODO(gri) should we assume now that bounds always exist? // (no bound == empty interface) if bound != nil { - bound = check.subst(tname.pos, bound, smap, nil) - tname.typ.(*TypeParam).bound = bound + bound = check.subst(tpar.obj.pos, bound, smap, nil) + tpar.bound = bound } } } -- cgit v1.2.3-54-g00ecf