aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/typeparam.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/typeparam.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/typeparam.go')
-rw-r--r--src/cmd/compile/internal/types2/typeparam.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/types2/typeparam.go b/src/cmd/compile/internal/types2/typeparam.go
index f666fae7ed..0d76dd1a6e 100644
--- a/src/cmd/compile/internal/types2/typeparam.go
+++ b/src/cmd/compile/internal/types2/typeparam.go
@@ -84,7 +84,7 @@ func (t *TypeParam) Underlying() Type { return t }
func (t *TypeParam) String() string { return TypeString(t, nil) }
// TParamList holds a list of type parameters bound to a type.
-type TParamList struct{ tparams []*TypeName }
+type TParamList struct{ tparams []*TypeParam }
// Len returns the number of type parameters in the list.
// It is safe to call on a nil receiver.
@@ -93,23 +93,22 @@ func (tps *TParamList) Len() int {
}
// At returns the i'th type parameter in the list.
-func (tps *TParamList) At(i int) *TypeName {
+func (tps *TParamList) At(i int) *TypeParam {
return tps.list()[i]
}
-func (tps *TParamList) list() []*TypeName {
+func (tps *TParamList) list() []*TypeParam {
if tps == nil {
return nil
}
return tps.tparams
}
-func bindTParams(list []*TypeName) *TParamList {
+func bindTParams(list []*TypeParam) *TParamList {
if len(list) == 0 {
return nil
}
- for i, tp := range list {
- typ := tp.Type().(*TypeParam)
+ for i, typ := range list {
if typ.index >= 0 {
panic("type parameter bound more than once")
}