]> Cypherpunks repositories - gostls13.git/commit
[dev.typeparams] cmd/compile/internal/types2: clean up index expr implementation...
authorRobert Griesemer <gri@golang.org>
Fri, 2 Jul 2021 22:41:28 +0000 (15:41 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 7 Jul 2021 23:42:12 +0000 (23:42 +0000)
commit03ec8de24b6fc8a2abeb4013ef603f5cdef9f874
tree0522ea7572f66479f5e672ef30ea2f112438a09b
parent47547d8508ab416e28992e0e0965c9c25f840848
[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>
src/cmd/compile/internal/types2/index.go
src/cmd/compile/internal/types2/testdata/check/typeparams.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue45635.go2
src/cmd/compile/internal/types2/typeparam.go
src/cmd/compile/internal/types2/typeset.go
src/cmd/compile/internal/types2/typestring.go
src/cmd/compile/internal/types2/union.go