@@ -60,24 +60,32 @@ func (t *TypeParam) _SetId(id uint64) {
60
60
t .id = id
61
61
}
62
62
63
- // TODO(rfindley): document the Bound and SetBound methods.
63
+ // Constraint returns the type constraint specified for t.
64
+ func (t * TypeParam ) Constraint () Type {
65
+ // compute the type set if possible (we may not have an interface)
66
+ if iface , _ := under (t .bound ).(* Interface ); iface != nil {
67
+ // use the type bound position if we have one
68
+ pos := token .NoPos
69
+ if n , _ := t .bound .(* Named ); n != nil {
70
+ pos = n .obj .pos
71
+ }
72
+ computeTypeSet (t .check , pos , iface )
73
+ }
74
+ return t .bound
75
+ }
64
76
77
+ // Bound returns the underlying type of the type parameter's
78
+ // constraint.
79
+ // Deprecated for external use. Use Constraint instead.
65
80
func (t * TypeParam ) Bound () * Interface {
66
- // we may not have an interface (error reported elsewhere)
67
- iface , _ := under (t .bound ).(* Interface )
68
- if iface == nil {
69
- return & emptyInterface
81
+ if iface , _ := under (t .Constraint ()).(* Interface ); iface != nil {
82
+ return iface
70
83
}
71
- // use the type bound position if we have one
72
- pos := token .NoPos
73
- if n , _ := t .bound .(* Named ); n != nil {
74
- pos = n .obj .pos
75
- }
76
- // TODO(rFindley) switch this to an unexported method on Checker.
77
- computeTypeSet (t .check , pos , iface )
78
- return iface
84
+ return & emptyInterface
79
85
}
80
86
87
+ // TODO(rfindley): document the SetBound methods.
88
+
81
89
func (t * TypeParam ) SetBound (bound Type ) {
82
90
if bound == nil {
83
91
panic ("internal error: bound must not be nil" )
0 commit comments