diff options
author | Robert Griesemer <gri@golang.org> | 2021-07-23 10:26:07 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-07-26 20:53:16 +0000 |
commit | d6753fd491c101e71f5e86d87b44d396828e2deb (patch) | |
tree | 56aba4c2257c74f87d91022b9d32fd55e706ab26 /src/cmd/compile/internal/types2/typeparam.go | |
parent | 9e3274bb3d8170efba1c0b42fa09334f1d3f6677 (diff) | |
download | go-d6753fd491c101e71f5e86d87b44d396828e2deb.tar.gz go-d6753fd491c101e71f5e86d87b44d396828e2deb.zip |
[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>
Diffstat (limited to 'src/cmd/compile/internal/types2/typeparam.go')
-rw-r--r-- | src/cmd/compile/internal/types2/typeparam.go | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/types2/typeparam.go b/src/cmd/compile/internal/types2/typeparam.go index b73b4edf79..0aca227c0a 100644 --- a/src/cmd/compile/internal/types2/typeparam.go +++ b/src/cmd/compile/internal/types2/typeparam.go @@ -53,20 +53,28 @@ func (t *TypeParam) SetId(id uint64) { t.id = id } -func (t *TypeParam) Bound() *Interface { - // we may not have an interface (error reported elsewhere) - iface, _ := under(t.bound).(*Interface) - if iface == nil { - return &emptyInterface +// Constraint returns the type constraint specified for t. +func (t *TypeParam) Constraint() Type { + // compute the type set if possible (we may not have an interface) + if iface, _ := under(t.bound).(*Interface); iface != nil { + // use the type bound position if we have one + pos := nopos + if n, _ := t.bound.(*Named); n != nil { + pos = n.obj.pos + } + computeTypeSet(t.check, pos, iface) } - // use the type bound position if we have one - pos := nopos - if n, _ := t.bound.(*Named); n != nil { - pos = n.obj.pos + 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 } - // TODO(gri) switch this to an unexported method on Checker. - computeTypeSet(t.check, pos, iface) - return iface + return &emptyInterface } func (t *TypeParam) SetBound(bound Type) { |