aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/testdata
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-09-29 11:14:05 -0700
committerRobert Griesemer <gri@golang.org>2021-10-01 17:18:20 +0000
commit5279e534b5ced1eaea19e8b75968498287ff6228 (patch)
treece9feca68f08d6cff663f7d310e70046e717beaa /src/cmd/compile/internal/syntax/testdata
parentf19b2d50c6d9918c1c121ccd8cb2a4f4a2d3f30b (diff)
downloadgo-5279e534b5ced1eaea19e8b75968498287ff6228.tar.xz
cmd/compile/internal/syntax: allow eliding interface in constraint literals
This CL permits an arbitrary type as well as the type sets ~T and A|B in constraint position, without the need of a surrrounding interface. For instance, the type parameter list [P interface{ ~map[K]V }, K comparable, V interface{ ~string }] may be written as [P ~map[K]V, K comparable, V ~string] The feature must be enabled explicitly with the AllowTypeSets mode and is only available if AllowGenerics is set as well. For #48424. Change-Id: Ic70bb97a49ff75e67e040853eac10e6aed0fef1a Reviewed-on: https://go-review.googlesource.com/c/go/+/353133 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/syntax/testdata')
-rw-r--r--src/cmd/compile/internal/syntax/testdata/typeset.go272
1 files changed, 72 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/syntax/testdata/typeset.go2 b/src/cmd/compile/internal/syntax/testdata/typeset.go2
new file mode 100644
index 0000000000..a173bb1d4f
--- /dev/null
+++ b/src/cmd/compile/internal/syntax/testdata/typeset.go2
@@ -0,0 +1,72 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file contains test cases for typeset-only constraint elements.
+// TODO(gri) gofmt once/if gofmt supports this notation.
+
+package p
+
+type (
+ _[_ t] t
+ _[_ ~t] t
+ _[_ t|t] t
+ _[_ ~t|t] t
+ _[_ t|~t] t
+ _[_ ~t|~t] t
+
+ _[_ t, _, _ t|t] t
+ _[_ t, _, _ ~t|t] t
+ _[_ t, _, _ t|~t] t
+ _[_ t, _, _ ~t|~t] t
+
+ _[_ t.t] t
+ _[_ ~t.t] t
+ _[_ t.t|t.t] t
+ _[_ ~t.t|t.t] t
+ _[_ t.t|~t.t] t
+ _[_ ~t.t|~t.t] t
+
+ _[_ t, _, _ t.t|t.t] t
+ _[_ t, _, _ ~t.t|t.t] t
+ _[_ t, _, _ t.t|~t.t] t
+ _[_ t, _, _ ~t.t|~t.t] t
+
+ _[_ struct{}] t
+ _[_ ~struct{}] t
+
+ _[_ struct{}|t] t
+ _[_ ~struct{}|t] t
+ _[_ struct{}|~t] t
+ _[_ ~struct{}|~t] t
+
+ _[_ t|struct{}] t
+ _[_ ~t|struct{}] t
+ _[_ t|~struct{}] t
+ _[_ ~t|~struct{}] t
+)
+
+// Single-expression type parameter lists and those that don't start
+// with a (type parameter) name are considered array sizes.
+// The term must be a valid expression (it could be a type - and then
+// a type-checker will complain - but we don't allow ~ in the expr).
+type (
+ _[t] t
+ _[/* ERROR unexpected ~ */ ~t] t
+ _[t|t] t
+ _[/* ERROR unexpected ~ */ ~t|t] t
+ _[t| /* ERROR unexpected ~ */ ~t] t
+ _[/* ERROR unexpected ~ */ ~t|~t] t
+)
+
+type (
+ _[_ t, t /* ERROR missing type constraint */ ] t
+ _[_ ~t, t /* ERROR missing type constraint */ ] t
+ _[_ t, /* ERROR type parameters must be named */ ~t] t
+ _[_ ~t, /* ERROR type parameters must be named */ ~t] t
+
+ _[_ t|t, /* ERROR type parameters must be named */ t|t] t
+ _[_ ~t|t, /* ERROR type parameters must be named */ t|t] t
+ _[_ t|t, /* ERROR type parameters must be named */ ~t|t] t
+ _[_ ~t|t, /* ERROR type parameters must be named */ ~t|t] t
+)