-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile/internal/syntax: allow eliding interface in constraint li…
…terals 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>
- Loading branch information
Showing
6 changed files
with
133 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |