1
0
mirror of https://github.com/golang/go synced 2024-11-17 14:44:44 -07:00

[dev.typeparams] cmd/compile/internal/types2: implement TypeParam.Constraint

Change-Id: I95a96f9dbd199cee3a4be8f42cd64e7f44ba5e5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/336989
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2021-07-23 10:26:07 -07:00
parent 9e3274bb3d
commit d6753fd491

View File

@ -53,21 +53,29 @@ func (t *TypeParam) SetId(id uint64) {
t.id = id t.id = id
} }
func (t *TypeParam) Bound() *Interface { // Constraint returns the type constraint specified for t.
// we may not have an interface (error reported elsewhere) func (t *TypeParam) Constraint() Type {
iface, _ := under(t.bound).(*Interface) // compute the type set if possible (we may not have an interface)
if iface == nil { if iface, _ := under(t.bound).(*Interface); iface != nil {
return &emptyInterface
}
// use the type bound position if we have one // use the type bound position if we have one
pos := nopos pos := nopos
if n, _ := t.bound.(*Named); n != nil { if n, _ := t.bound.(*Named); n != nil {
pos = n.obj.pos pos = n.obj.pos
} }
// TODO(gri) switch this to an unexported method on Checker.
computeTypeSet(t.check, pos, iface) computeTypeSet(t.check, pos, iface)
}
return t.bound
}
// Bound returns the underlying type of the type parameter's
// constraint.
// Deprecated for external use. Use Constraint instead.
func (t *TypeParam) Bound() *Interface {
if iface, _ := under(t.Constraint()).(*Interface); iface != nil {
return iface return iface
} }
return &emptyInterface
}
func (t *TypeParam) SetBound(bound Type) { func (t *TypeParam) SetBound(bound Type) {
if bound == nil { if bound == nil {