aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/typeset.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-07-02 15:41:28 -0700
committerRobert Griesemer <gri@golang.org>2021-07-07 23:42:12 +0000
commit03ec8de24b6fc8a2abeb4013ef603f5cdef9f874 (patch)
tree0522ea7572f66479f5e672ef30ea2f112438a09b /src/cmd/compile/internal/types2/typeset.go
parent47547d8508ab416e28992e0e0965c9c25f840848 (diff)
downloadgo-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/typeset.go')
-rw-r--r--src/cmd/compile/internal/types2/typeset.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/typeset.go b/src/cmd/compile/internal/types2/typeset.go
index 265221501f..6ff8563974 100644
--- a/src/cmd/compile/internal/types2/typeset.go
+++ b/src/cmd/compile/internal/types2/typeset.go
@@ -75,6 +75,21 @@ func (s *TypeSet) String() string {
// ----------------------------------------------------------------------------
// Implementation
+// underIs reports whether f returned true for the underlying types of the
+// enumerable types in the type set s. If the type set comprises all types
+// f is called once with the top type; if the type set is empty, the result
+// is false.
+func (s *TypeSet) underIs(f func(Type) bool) bool {
+ switch t := s.types.(type) {
+ case nil:
+ return f(theTop)
+ default:
+ return f(t)
+ case *Union:
+ return t.underIs(f)
+ }
+}
+
// topTypeSet may be used as type set for the empty interface.
var topTypeSet TypeSet