diff options
author | Robert Findley <rfindley@google.com> | 2021-08-13 15:52:12 -0400 |
---|---|---|
committer | Robert Findley <rfindley@google.com> | 2021-08-19 15:05:05 +0000 |
commit | 69d8fbec7ab74b3b0f8b689a9a251bdf621936aa (patch) | |
tree | dfcf4bf1cd282419062e1754d188c3bc7b32b2ea /src/cmd/compile/internal/types2/subst.go | |
parent | 3bdc1799d6ce441d7a972faf1452e34b6dce0826 (diff) | |
download | go-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/types2/subst.go')
-rw-r--r-- | src/cmd/compile/internal/types2/subst.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/types2/subst.go b/src/cmd/compile/internal/types2/subst.go index 2c0fc6e391..edbbdb4758 100644 --- a/src/cmd/compile/internal/types2/subst.go +++ b/src/cmd/compile/internal/types2/subst.go @@ -35,13 +35,12 @@ func (m substMap) lookup(tpar *TypeParam) Type { return tpar } -// subst returns the type typ with its type parameters tpars replaced by -// the corresponding type arguments targs, recursively. -// subst is functional in the sense that it doesn't modify the incoming -// type. If a substitution took place, the result type is different from -// from the incoming type. +// subst returns the type typ with its type parameters tpars replaced by the +// corresponding type arguments targs, recursively. subst doesn't modify the +// incoming type. If a substitution took place, the result type is different +// from from the incoming type. // -// If the given typMap is nil and check is non-nil, check.typMap is used. +// If the given typMap is non-nil, it is used in lieu of check.typMap. func (check *Checker) subst(pos syntax.Pos, typ Type, smap substMap, typMap map[string]*Named) Type { if smap.empty() { return typ |