5
5
package types
6
6
7
7
import (
8
+ "fmt"
8
9
"go/token"
9
10
"sort"
10
11
)
@@ -633,12 +634,19 @@ func (t *Interface) Complete() *Interface {
633
634
allTypes := t .types
634
635
635
636
for _ , typ := range t .embeddeds {
636
- typ := typ .Interface ()
637
- typ .Complete ()
638
- for _ , m := range typ .allMethods {
637
+ utyp := typ .Under ()
638
+ etyp := utyp .Interface ()
639
+ if etyp == nil {
640
+ if utyp != Typ [Invalid ] {
641
+ panic (fmt .Sprintf ("%s is not an interface" , typ ))
642
+ }
643
+ continue
644
+ }
645
+ etyp .Complete ()
646
+ for _ , m := range etyp .allMethods {
639
647
addMethod (m , false )
640
648
}
641
- allTypes = intersect (allTypes , typ . types )
649
+ allTypes = intersect (allTypes , etyp . allTypes )
642
650
}
643
651
644
652
for i := 0 ; i < len (todo ); i += 2 {
@@ -795,6 +803,7 @@ func (t *Named) AddMethod(m *Func) {
795
803
796
804
// A TypeParam represents a type parameter type.
797
805
type TypeParam struct {
806
+ check * Checker // for lazy type bound completion
798
807
id uint64 // unique id
799
808
ptr bool // pointer designation
800
809
obj * TypeName // corresponding type name
@@ -806,7 +815,7 @@ type TypeParam struct {
806
815
// NewTypeParam returns a new TypeParam.
807
816
func (check * Checker ) NewTypeParam (ptr bool , obj * TypeName , index int , bound Type ) * TypeParam {
808
817
assert (bound != nil )
809
- typ := & TypeParam {id : check .nextId , ptr : ptr , obj : obj , index : index , bound : bound }
818
+ typ := & TypeParam {check : check , id : check .nextId , ptr : ptr , obj : obj , index : index , bound : bound }
810
819
check .nextId ++
811
820
if obj .typ == nil {
812
821
obj .typ = typ
@@ -816,7 +825,12 @@ func (check *Checker) NewTypeParam(ptr bool, obj *TypeName, index int, bound Typ
816
825
817
826
func (t * TypeParam ) Bound () * Interface {
818
827
iface := t .bound .Interface ()
819
- iface .Complete () // TODO(gri) should we use check.completeInterface instead?
828
+ // use the type bound position if we have one
829
+ pos := token .NoPos
830
+ if n , _ := t .bound .(* Named ); n != nil {
831
+ pos = n .obj .pos
832
+ }
833
+ t .check .completeInterface (pos , iface )
820
834
return iface
821
835
}
822
836
0 commit comments