]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: constraints may be parenthesized and that includes "any"
authorRobert Griesemer <gri@golang.org>
Tue, 23 Feb 2021 20:47:08 +0000 (12:47 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 23 Feb 2021 21:49:20 +0000 (21:49 +0000)
Change-Id: I9a234cc1f04ca762375b51ec8ef009fb264c7ed1
Reviewed-on: https://go-review.googlesource.com/c/go/+/295689
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>
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/testdata/typeparams.go2
src/go/types/decl.go
src/go/types/testdata/typeparams.go2

index 677172d40f92fa6bad79686214842546bd5fa9cb..f0a037adb01ba64ade74374489dd0dbb0f7ae1d6 100644 (file)
@@ -707,7 +707,7 @@ func (check *Checker) collectTypeParams(list []*syntax.Field) (tparams []*TypeNa
                // The predeclared identifier "any" is visible only as a constraint
                // in a type parameter list. Look for it before general constraint
                // resolution.
-               if tident, _ := f.Type.(*syntax.Name); tident != nil && tident.Value == "any" && check.lookup("any") == nil {
+               if tident, _ := unparen(f.Type).(*syntax.Name); tident != nil && tident.Value == "any" && check.lookup("any") == nil {
                        bound = universeAny
                } else {
                        bound = check.typ(f.Type)
index 04f563029fc0c22e11163a76262ec04dad0205e6..41306b6e23c52d24b755aadb09c4d2c21a5d6438 100644 (file)
@@ -19,6 +19,10 @@ func _[_ any](x int) int
 func _[T any](T /* ERROR redeclared */ T)()
 func _[T, T /* ERROR redeclared */ any]()
 
+// Constraints (incl. any) may be parenthesized.
+func _[_ (any)]() {}
+func _[_ (interface{})]() {}
+
 func reverse[T any](list []T) []T {
         rlist := make([]T, len(list))
         i := len(list)
index c97b1a66bb975aed9b2068fe3f1e9f7e5dad6bbf..1134607e92c2fe35bb61e54746379ff624940728 100644 (file)
@@ -726,7 +726,7 @@ func (check *Checker) collectTypeParams(list *ast.FieldList) (tparams []*TypeNam
                // The predeclared identifier "any" is visible only as a constraint
                // in a type parameter list. Look for it before general constraint
                // resolution.
-               if tident, _ := f.Type.(*ast.Ident); tident != nil && tident.Name == "any" && check.lookup("any") == nil {
+               if tident, _ := unparen(f.Type).(*ast.Ident); tident != nil && tident.Name == "any" && check.lookup("any") == nil {
                        bound = universeAny
                } else {
                        bound = check.typ(f.Type)
index 2dd8f64dc0b9771357f57e1e138b4e6cce734be0..bb7f016a83f5c421bf15ee1a26233d80785818af 100644 (file)
@@ -19,6 +19,10 @@ func _[_ any](x int) int
 func _[T any](T /* ERROR redeclared */ T)()
 func _[T, T /* ERROR redeclared */ any]()
 
+// Constraints (incl. any) may be parenthesized.
+func _[_ (any)]() {}
+func _[_ (interface{})]() {}
+
 func reverse[T any](list []T) []T {
         rlist := make([]T, len(list))
         i := len(list)