Skip to content

Commit 66f0d35

Browse files
committed
go/types: reduce number of delayed functions
This is a port of CL 348018 to go/types. It differs from that CL due to the way that field lists are represented in go/ast. Change-Id: Ib5a0243b44d0bf9e95d039f624c668f8c329f8fa Reviewed-on: https://go-review.googlesource.com/c/go/+/348691 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent d2a77f1 commit 66f0d35

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/go/types/decl.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

680699
func (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-
720720
func (check *Checker) collectMethods(obj *TypeName) {
721721
// get associated methods
722722
// (Checker.collectObjects only collects methods with non-blank names;

0 commit comments

Comments
 (0)