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>
This commit is contained in:
Robert Griesemer 2021-09-29 11:14:05 -07:00
parent f19b2d50c6
commit 5279e534b5
6 changed files with 133 additions and 22 deletions

View file

@ -130,7 +130,7 @@ func testSyntaxErrors(t *testing.T, filename string) {
var mode Mode
if strings.HasSuffix(filename, ".go2") {
mode = AllowGenerics | AllowTypeLists
mode = AllowGenerics | AllowTypeSets | AllowTypeLists
}
ParseFile(filename, func(err error) {
e, ok := err.(Error)