]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.18] go/types, types2: correctly include comparable in type set...
authorRobert Griesemer <gri@golang.org>
Fri, 4 Mar 2022 23:07:17 +0000 (15:07 -0800)
committerDmitri Shuralyov <dmitshur@golang.org>
Tue, 8 Mar 2022 00:42:10 +0000 (00:42 +0000)
commitf913f9dd1aea3d0a4754f63a30af6b8e2e50d9c8
tree69f73bc6c75ebc99f1193adc9d0cfec36c3729a5
parenta54f962c29549f343a6b10559e14ca4d690cdb76
[release-branch.go1.18] 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>
(cherry picked from commit 7dc6c5ec34ca6780e8eac1760116ff69d0c27d7a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/390419
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@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