aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/importer
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2021-08-13 15:52:12 -0400
committerRobert Findley <rfindley@google.com>2021-08-19 15:05:05 +0000
commit69d8fbec7ab74b3b0f8b689a9a251bdf621936aa (patch)
treedfcf4bf1cd282419062e1754d188c3bc7b32b2ea /src/cmd/compile/internal/importer
parent3bdc1799d6ce441d7a972faf1452e34b6dce0826 (diff)
downloadgo-69d8fbec7ab74b3b0f8b689a9a251bdf621936aa.tar.gz
go-69d8fbec7ab74b3b0f8b689a9a251bdf621936aa.zip
cmd/compile/internal/types2: return an error from Instantiate
Change Instantiate to be a function (not a method) and return an error. Introduce an ArgumentError type to report information about which type argument led to an error during verification. This resolves a few concerns with the current API: - The Checker method set was previously just Files. It is somewhat odd to add an additional method for instantiation. Passing the checker as an argument seems cleaner. - pos, posList, and verify were bound together. In cases where no verification is required, the call site was somewhat cluttered. - Callers will likely want to access structured information about why type information is invalid, and also may not have access to position information. Returning an argument index solves both these problems; if callers want to associate errors with an argument position, they can do this via the resulting index. We may want to make the first argument an opaque environment rather than a Checker. Change-Id: I3bc56d205c13d832b538401a4c91d3917c041225 Reviewed-on: https://go-review.googlesource.com/c/go/+/342152 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/importer')
-rw-r--r--src/cmd/compile/internal/importer/iimport.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/importer/iimport.go b/src/cmd/compile/internal/importer/iimport.go
index a317dfc34a..ac5ec7c8f2 100644
--- a/src/cmd/compile/internal/importer/iimport.go
+++ b/src/cmd/compile/internal/importer/iimport.go
@@ -652,7 +652,9 @@ func (r *importReader) doType(base *types2.Named) types2.Type {
if r.p.exportVersion < iexportVersionGenerics {
errorf("unexpected instantiation type")
}
- pos := r.pos()
+ // pos does not matter for instances: they are positioned on the original
+ // type.
+ _ = r.pos()
len := r.uint64()
targs := make([]types2.Type, len)
for i := range targs {
@@ -661,8 +663,8 @@ func (r *importReader) doType(base *types2.Named) types2.Type {
baseType := r.typ()
// The imported instantiated type doesn't include any methods, so
// we must always use the methods of the base (orig) type.
- var check *types2.Checker // TODO provide a non-nil *Checker
- t := check.Instantiate(pos, baseType, targs, nil, false)
+ // TODO provide a non-nil *Checker
+ t, _ := types2.Instantiate(nil, baseType, targs, false)
return t
case unionType: