aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/testdata/examples
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-05-27 19:03:16 -0700
committerRobert Griesemer <gri@golang.org>2021-06-02 23:19:26 +0000
commit848b58e47357965dc5a61fb0ae5535da717e2633 (patch)
treedd6a3154d729d12cc059eee6418657ab7c747609 /src/cmd/compile/internal/types2/testdata/examples
parent97cb0113a358a24931bc91c956da0cb023f2776c (diff)
downloadgo-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.go214
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 */ ) }