aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/testdata
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-06-02 17:05:37 -0700
committerRobert Griesemer <gri@golang.org>2021-06-03 03:55:37 +0000
commit10d6b36ca3f8d48a667742eee791dacbcfc888cd (patch)
tree019780ec6161df9fe256962e9cdf0c711a493bca /src/cmd/compile/internal/types2/testdata
parent8cdce85bdf80f6aa9bd3979d3ecab6565512b736 (diff)
downloadgo-10d6b36ca3f8d48a667742eee791dacbcfc888cd.tar.gz
go-10d6b36ca3f8d48a667742eee791dacbcfc888cd.zip
[dev.typeparams] cmd/compile/internal/types2: disallow ~T where T is a defined type or an interface
Change-Id: I35f6f43db00d56847da48320308f2fcfff924738 Reviewed-on: https://go-review.googlesource.com/c/go/+/324570 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/testdata')
-rw-r--r--src/cmd/compile/internal/types2/testdata/check/typeinst2.go24
-rw-r--r--src/cmd/compile/internal/types2/testdata/examples/constraints.go29
-rw-r--r--src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go24
3 files changed, 13 insertions, 4 deletions
diff --git a/src/cmd/compile/internal/types2/testdata/check/typeinst2.go2 b/src/cmd/compile/internal/types2/testdata/check/typeinst2.go2
index 37745dfcba..14d8f0ea8c 100644
--- a/src/cmd/compile/internal/types2/testdata/check/typeinst2.go2
+++ b/src/cmd/compile/internal/types2/testdata/check/typeinst2.go2
@@ -176,12 +176,12 @@ type _ interface {
// Interface type lists can contain any type, incl. *Named types.
// Verify that we use the underlying type to compute the operational type.
type MyInt int
-func add1[T interface{~MyInt}](x T) T {
+func add1[T interface{MyInt}](x T) T {
return x + 1
}
type MyString string
-func double[T interface{~MyInt | ~MyString}](x T) T {
+func double[T interface{MyInt|MyString}](x T) T {
return x + x
}
diff --git a/src/cmd/compile/internal/types2/testdata/examples/constraints.go2 b/src/cmd/compile/internal/types2/testdata/examples/constraints.go2
index f6291ccf7d..efefaa2a25 100644
--- a/src/cmd/compile/internal/types2/testdata/examples/constraints.go2
+++ b/src/cmd/compile/internal/types2/testdata/examples/constraints.go2
@@ -24,6 +24,15 @@ type (
_ interface{int|interface /* ERROR cannot use interface */ {}}
)
+type (
+ // Tilde is not permitted on defined types or interfaces.
+ foo int
+ bar interface{}
+ _ interface{foo}
+ _ interface{~ /* ERROR invalid use of ~ */ foo }
+ _ interface{~ /* ERROR invalid use of ~ */ bar }
+)
+
// Multiple embedded union elements are intersected. The order in which they
// appear in the interface doesn't matter since intersection is a symmetric
// operation.
diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go2
index 39ec5d7b30..6d002f5d2f 100644
--- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go2
+++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go2
@@ -36,8 +36,8 @@ func bar8[A foo8[A]](a A) {}
func main8() {}
// crash 9
-type foo9[A any] interface { ~/* ERROR cannot use interface */ foo9[A] }
-func _() { var _ = new(foo9 /* ERROR interface contains type constraints */ [int]) }
+type foo9[A any] interface { foo9 /* ERROR illegal cycle */ [A] }
+func _() { var _ = new(foo9 /* ERROR illegal cycle */ [int]) }
// crash 12
var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len /* ERROR must be called */ /* ERROR must be called */ )]c /* ERROR undeclared */ /* ERROR undeclared */