mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
f19b2d50c6
commit
5279e534b5
6 changed files with 133 additions and 22 deletions
|
|
@ -26,11 +26,11 @@ var (
|
|||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics)
|
||||
ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics|AllowTypeSets)
|
||||
}
|
||||
|
||||
func TestVerify(t *testing.T) {
|
||||
ast, err := ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics)
|
||||
ast, err := ParseFile(*src_, func(err error) { t.Error(err) }, nil, AllowGenerics|AllowTypeSets)
|
||||
if err != nil {
|
||||
return // error already reported
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ func TestParseGo2(t *testing.T) {
|
|||
for _, fi := range list {
|
||||
name := fi.Name()
|
||||
if !fi.IsDir() && !strings.HasPrefix(name, ".") {
|
||||
ParseFile(filepath.Join(dir, name), func(err error) { t.Error(err) }, nil, AllowGenerics|AllowTypeLists)
|
||||
ParseFile(filepath.Join(dir, name), func(err error) { t.Error(err) }, nil, AllowGenerics|AllowTypeSets|AllowTypeLists)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue