]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.typeparams] cmd/compile/internal/types2: accept embedded interface elements
authorRobert Griesemer <gri@golang.org>
Thu, 20 May 2021 22:13:04 +0000 (15:13 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 24 May 2021 23:16:07 +0000 (23:16 +0000)
commit5770d7a63743ddfd0e78877f162cbbf18ffb9c1d
treeee9d3626479a6ac8589dc7b446c24365281456bc
parentcc7ceea5859beb5569d1a278e389ae7dd7d13f8b
[dev.typeparams] cmd/compile/internal/types2: accept embedded interface elements

Accept embedded interface elements of the form ~T or A|B and
treat them like type lists: for now the elements of a union
cannot be interfaces. Also, translate existing style "type"-
lists in interfaces into interface elements: "type a, b, c"
becomes a union element "~a|~b|~c" which in turn is handled
internally like a type list.

For now, "~" is still ignored and type lists are mapped to
Sum types as before, thus ensuring that all existing tests
work as before (with some minor adjustments).

Introduced a new Union type to represent union elements.
For now they don't make it past interface completion where
they are represented as a Sum type. Thus, except for printing
(and the respective tests) and substitution for interfaces,
the various type switches ignore Union types. In a next step,
we'll replace Sum types with union types and then consider
the ~ functionality as well.

Because union elements are no different from embedded interfaces
we don't need a separate Interface.types field anymore. Removed.

For #45346.

Change-Id: I98ac3286aea9d706e98aee80241d4712ed99af08
Reviewed-on: https://go-review.googlesource.com/c/go/+/321689
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
24 files changed:
src/cmd/compile/internal/noder/types.go
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/index.go
src/cmd/compile/internal/types2/infer.go
src/cmd/compile/internal/types2/interface.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/sanitize.go
src/cmd/compile/internal/types2/sizeof_test.go
src/cmd/compile/internal/types2/sizes.go
src/cmd/compile/internal/types2/subst.go
src/cmd/compile/internal/types2/testdata/check/decls0.src
src/cmd/compile/internal/types2/testdata/check/issues.src
src/cmd/compile/internal/types2/testdata/check/typeinst2.go2
src/cmd/compile/internal/types2/testdata/examples/constraints.go2 [new file with mode: 0644]
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39693.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39711.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39723.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39948.go2
src/cmd/compile/internal/types2/type.go
src/cmd/compile/internal/types2/typestring.go
src/cmd/compile/internal/types2/typestring_test.go
src/cmd/compile/internal/types2/unify.go
src/cmd/compile/internal/types2/union.go [new file with mode: 0644]