diff options
author | Robert Griesemer <gri@golang.org> | 2021-08-23 18:29:38 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-08-24 16:36:48 +0000 |
commit | 1ff0554b5318d5a39e2b26a9c84330e6aa47b1c6 (patch) | |
tree | 14a98ed5b571cdf8bcdf847077e7ee04b9869de2 /src/cmd/compile/internal/importer | |
parent | bd9776357732eb3a3c635427bb3591e4cbc79cc5 (diff) | |
download | go-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/importer')
-rw-r--r-- | src/cmd/compile/internal/importer/iimport.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cmd/compile/internal/importer/iimport.go b/src/cmd/compile/internal/importer/iimport.go index 4384e59c30..a46971d0a7 100644 --- a/src/cmd/compile/internal/importer/iimport.go +++ b/src/cmd/compile/internal/importer/iimport.go @@ -309,7 +309,7 @@ func (r *importReader) obj(name string) { r.declare(types2.NewConst(pos, r.currPkg, name, typ, val)) case 'F', 'G': - var tparams []*types2.TypeName + var tparams []*types2.TypeParam if tag == 'G' { tparams = r.tparamList() } @@ -318,7 +318,7 @@ func (r *importReader) obj(name string) { r.declare(types2.NewFunc(pos, r.currPkg, name, sig)) case 'T', 'U': - var tparams []*types2.TypeName + var tparams []*types2.TypeParam if tag == 'U' { tparams = r.tparamList() } @@ -347,9 +347,9 @@ func (r *importReader) obj(name string) { // typeparams being used in the method sig/body). targs := baseType(msig.Recv().Type()).TArgs() if len(targs) > 0 { - rparams := make([]*types2.TypeName, len(targs)) + rparams := make([]*types2.TypeParam, len(targs)) for i, targ := range targs { - rparams[i] = types2.AsTypeParam(targ).Obj() + rparams[i] = types2.AsTypeParam(targ) } msig.SetRParams(rparams) } @@ -690,15 +690,15 @@ func (r *importReader) signature(recv *types2.Var) *types2.Signature { return types2.NewSignature(recv, params, results, variadic) } -func (r *importReader) tparamList() []*types2.TypeName { +func (r *importReader) tparamList() []*types2.TypeParam { n := r.uint64() if n == 0 { return nil } - xs := make([]*types2.TypeName, n) + xs := make([]*types2.TypeParam, n) for i := range xs { typ := r.typ() - xs[i] = types2.AsTypeParam(typ).Obj() + xs[i] = types2.AsTypeParam(typ) } return xs } |