@@ -663,18 +663,37 @@ func (check *Checker) collectTypeParams(dst **TypeParamList, list *ast.FieldList
663663
664664 index := 0
665665 var bound Type
666+ var bounds []Type
667+ var posns []positioner // bound positions
666668 for _ , f := range list .List {
667669 if f .Type == nil {
668670 goto next
669671 }
670- bound = check .boundType (f .Type )
672+ // The predeclared identifier "any" is visible only as a type bound in a type parameter list.
673+ // If we allow "any" for general use, this if-statement can be removed (issue #33232).
674+ if name , _ := unparen (f .Type ).(* ast.Ident ); name != nil && name .Name == "any" && check .lookup ("any" ) == universeAny {
675+ bound = universeAny .Type ()
676+ } else {
677+ bound = check .typ (f .Type )
678+ }
679+ bounds = append (bounds , bound )
680+ posns = append (posns , f .Type )
671681 for i := range f .Names {
672682 tparams [index + i ].bound = bound
673683 }
674684
675685 next:
676686 index += len (f .Names )
677687 }
688+
689+ check .later (func () {
690+ for i , bound := range bounds {
691+ u := under (bound )
692+ if _ , ok := u .(* Interface ); ! ok && u != Typ [Invalid ] {
693+ check .errorf (posns [i ], _Todo , "%s is not an interface" , bound )
694+ }
695+ }
696+ })
678697}
679698
680699func (check * Checker ) declareTypeParams (tparams []* TypeParam , names []* ast.Ident ) []* TypeParam {
@@ -698,25 +717,6 @@ func (check *Checker) declareTypeParams(tparams []*TypeParam, names []*ast.Ident
698717 return tparams
699718}
700719
701- // boundType type-checks the type expression e and returns its type, or Typ[Invalid].
702- // The type must be an interface, including the predeclared type "any".
703- func (check * Checker ) boundType (e ast.Expr ) Type {
704- // The predeclared identifier "any" is visible only as a type bound in a type parameter list.
705- // If we allow "any" for general use, this if-statement can be removed (issue #33232).
706- if name , _ := unparen (e ).(* ast.Ident ); name != nil && name .Name == "any" && check .lookup ("any" ) == universeAny {
707- return universeAny .Type ()
708- }
709-
710- bound := check .typ (e )
711- check .later (func () {
712- u := under (bound )
713- if _ , ok := u .(* Interface ); ! ok && u != Typ [Invalid ] {
714- check .errorf (e , _Todo , "%s is not an interface" , bound )
715- }
716- })
717- return bound
718- }
719-
720720func (check * Checker ) collectMethods (obj * TypeName ) {
721721 // get associated methods
722722 // (Checker.collectObjects only collects methods with non-blank names;
0 commit comments