]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: correctly include comparable in type set intersection
authorRobert Griesemer <gri@golang.org>
Fri, 4 Mar 2022 23:07:17 +0000 (15:07 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 7 Mar 2022 18:19:44 +0000 (18:19 +0000)
commit7dc6c5ec34ca6780e8eac1760116ff69d0c27d7a
tree257dfc8286ab092cb9616dd1ab1fe29dfbab598d
parentdcb6547b76c5818b55294e203e8f5057794b23cf
go/types, types2: correctly include comparable in type set intersection

The comparable bit was handled incorrectly. This CL establishes
a clear invariant for a type set's terms and its comparable bit
and correctly uses the bit when computing term intersections.

Relevant changes:

- Introduce a new function intersectTermLists that does the
  correct intersection computation.

Minor:

- Moved the comparable bit after terms in _TypeSet to make it
  clearer that they belong together.

- Simplify and clarify _TypeSet.IsAll predicate.

- Remove the IsTypeSet predicate which was only used for error
  reporting in union.go, and use the existing predicates instead.

- Rename/introduce local variables in computeInterfaceTypeSet
  for consistency and to avoid confusion.

- Update some tests whose output has changed because the comparable
  bit is now only set if we have have the set of all types.
  For instance, for interface{comparable; int} the type set doesn't
  set the comparable bit because the intersection of comparable and
  int is just int; etc.

- Add many more comments to make the code clearer.

Fixes #51472.

Change-Id: I8a5661eb1693a41a17ce5f70d7e10774301f38ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/390025
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
12 files changed:
src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue51472.go2 [new file with mode: 0644]
src/cmd/compile/internal/types2/typeset.go
src/cmd/compile/internal/types2/typeset_test.go
src/cmd/compile/internal/types2/union.go
src/cmd/compile/internal/types2/universe.go
src/go/types/testdata/fixedbugs/issue41124.go2
src/go/types/testdata/fixedbugs/issue51472.go2 [new file with mode: 0644]
src/go/types/typeset.go
src/go/types/typeset_test.go
src/go/types/union.go
src/go/types/universe.go