diff options
author | Robert Griesemer <gri@golang.org> | 2021-05-27 19:03:16 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-06-02 23:19:26 +0000 |
commit | 848b58e47357965dc5a61fb0ae5535da717e2633 (patch) | |
tree | dd6a3154d729d12cc059eee6418657ab7c747609 /src/cmd/compile/internal/types2/testdata/examples | |
parent | 97cb0113a358a24931bc91c956da0cb023f2776c (diff) | |
download | go-848b58e47357965dc5a61fb0ae5535da717e2633.tar.gz go-848b58e47357965dc5a61fb0ae5535da717e2633.zip |
[dev.typeparams] cmd/compile/internal/types2: clean up type set/union intersection
- Eliminate the need for bottom type: This is now represented by
an empty union (denoting the set of no types).
- Clean up type set intersection and incorporate tilde information
in intersection operation and satisfaction tests.
- Minor cleanups along the way.
- Note: The intersection algorithm does not always compute the
largest possible intersection. To be addressed in a follow-up CL.
Change-Id: I7fa19df5996da36a4d8f29300d30a0aa4d8a3e5c
Reviewed-on: https://go-review.googlesource.com/c/go/+/323354
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2/testdata/examples')
-rw-r--r-- | src/cmd/compile/internal/types2/testdata/examples/constraints.go2 | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/testdata/examples/constraints.go2 b/src/cmd/compile/internal/types2/testdata/examples/constraints.go2 index e8b3912884..f6291ccf7d 100644 --- a/src/cmd/compile/internal/types2/testdata/examples/constraints.go2 +++ b/src/cmd/compile/internal/types2/testdata/examples/constraints.go2 @@ -23,3 +23,17 @@ type ( _ interface{~ /* ERROR cannot use interface */ interface{}} _ interface{int|interface /* ERROR cannot use interface */ {}} ) + +// Multiple embedded union elements are intersected. The order in which they +// appear in the interface doesn't matter since intersection is a symmetric +// operation. + +type myInt1 int +type myInt2 int + +func _[T interface{ myInt1|myInt2; ~int }]() T { return T(0) } +func _[T interface{ ~int; myInt1|myInt2 }]() T { return T(0) } + +// Here the intersections are empty - there's no type that's in the type set of T. +func _[T interface{ myInt1|myInt2; int }]() T { return T(0 /* ERROR cannot convert */ ) } +func _[T interface{ int; myInt1|myInt2 }]() T { return T(0 /* ERROR cannot convert */ ) } |