aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/decl.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/decl.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/decl.go')
-rw-r--r--src/cmd/compile/internal/types2/decl.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go
index aa9710788a..342e1090de 100644
--- a/src/cmd/compile/internal/types2/decl.go
+++ b/src/cmd/compile/internal/types2/decl.go
@@ -582,7 +582,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named
}
func (check *Checker) collectTypeParams(list []*syntax.Field) *TParamList {
- tparams := make([]*TypeName, len(list))
+ tparams := make([]*TypeParam, len(list))
// Declare type parameters up-front.
// The scope of type parameters starts at the beginning of the type parameter
@@ -599,16 +599,16 @@ func (check *Checker) collectTypeParams(list []*syntax.Field) *TParamList {
if i == 0 || f.Type != list[i-1].Type {
bound = check.boundType(f.Type)
}
- tparams[i].typ.(*TypeParam).bound = bound
+ tparams[i].bound = bound
}
return bindTParams(tparams)
}
-func (check *Checker) declareTypeParam(name *syntax.Name) *TypeName {
- tpar := NewTypeName(name.Pos(), check.pkg, name.Value, nil)
- check.NewTypeParam(tpar, nil) // assigns type to tpar as a side-effect
- check.declare(check.scope, name, tpar, check.scope.pos) // TODO(gri) check scope position
+func (check *Checker) declareTypeParam(name *syntax.Name) *TypeParam {
+ tname := NewTypeName(name.Pos(), check.pkg, name.Value, nil)
+ tpar := check.NewTypeParam(tname, nil) // assigns type to tname as a side-effect
+ check.declare(check.scope, name, tname, check.scope.pos) // TODO(gri) check scope position
return tpar
}