mirror of
https://github.com/golang/go
synced 2024-11-19 03:44:40 -07:00
go/types, types2: constraints may be parenthesized and that includes "any"
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>
This commit is contained in:
parent
74903553bc
commit
0458d8c983
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
4
src/go/types/testdata/typeparams.go2
vendored
4
src/go/types/testdata/typeparams.go2
vendored
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user