diff options
author | Robert Griesemer <gri@golang.org> | 2021-07-02 15:41:28 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-07-07 23:42:12 +0000 |
commit | 03ec8de24b6fc8a2abeb4013ef603f5cdef9f874 (patch) | |
tree | 0522ea7572f66479f5e672ef30ea2f112438a09b /src/cmd/compile/internal/types2/typeparam.go | |
parent | 47547d8508ab416e28992e0e0965c9c25f840848 (diff) | |
download | go-03ec8de24b6fc8a2abeb4013ef603f5cdef9f874.tar.gz go-03ec8de24b6fc8a2abeb4013ef603f5cdef9f874.zip |
[dev.typeparams] cmd/compile/internal/types2: clean up index expr implementation for type parameters
This makes the implementation match the intended spec behavior:
Given an index expression a[x] where a is a type parameter, the
index expression is valid if the constraint for a satisfies the
following criteria:
- Either all types in the constraint type set are maps, or none
of them are.
- If the (type set) types are maps, they must all have the same
key type. (This may be too strict, perhaps it's sufficient to
ensure assignability, but we can always relax that later.)
- All (type set) types must have the same element types.
- If there are any arrays, a constant index must be in range for
the shortest array.
Change-Id: I8c094c11e6fc9496c293871ccf93e3814c881e6f
Reviewed-on: https://go-review.googlesource.com/c/go/+/332553
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/typeparam.go')
-rw-r--r-- | src/cmd/compile/internal/types2/typeparam.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/typeparam.go b/src/cmd/compile/internal/types2/typeparam.go index 5c74405912..b73b4edf79 100644 --- a/src/cmd/compile/internal/types2/typeparam.go +++ b/src/cmd/compile/internal/types2/typeparam.go @@ -78,3 +78,10 @@ func (t *TypeParam) SetBound(bound Type) { func (t *TypeParam) Underlying() Type { return t } func (t *TypeParam) String() string { return TypeString(t, nil) } + +// ---------------------------------------------------------------------------- +// Implementation + +func (t *TypeParam) underIs(f func(Type) bool) bool { + return t.Bound().typeSet().underIs(f) +} |