aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/signature.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-08-23 18:29:38 -0700
committerRobert Griesemer <gri@golang.org>2021-08-24 16:36:48 +0000
commit1ff0554b5318d5a39e2b26a9c84330e6aa47b1c6 (patch)
tree14a98ed5b571cdf8bcdf847077e7ee04b9869de2 /src/cmd/compile/internal/types2/signature.go
parentbd9776357732eb3a3c635427bb3591e4cbc79cc5 (diff)
downloadgo-1ff0554b5318d5a39e2b26a9c84330e6aa47b1c6.tar.gz
go-1ff0554b5318d5a39e2b26a9c84330e6aa47b1c6.zip
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 <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/signature.go')
-rw-r--r--src/cmd/compile/internal/types2/signature.go18
1 files changed, 9 insertions, 9 deletions
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
}
}
}