[dev.typeparams] go/types: print constraint info for type param operands

This is a clean port of CL 338309 to go/types.

Change-Id: Ie2c9e2ea51d6321af8bf149e43cd71b7ac282d13
Reviewed-on: https://go-review.googlesource.com/c/go/+/339676
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-08-03 21:39:53 -04:00 committed by Robert Findley
parent 3efc8f9a8d
commit b01e775e9c

View file

@ -159,16 +159,20 @@ func operandString(x *operand, qf Qualifier) string {
if hasType {
if x.typ != Typ[Invalid] {
var intro string
switch {
case isGeneric(x.typ):
intro = " of generic type "
case asTypeParam(x.typ) != nil:
intro = " of type parameter type "
default:
var tpar *TypeParam
if isGeneric(x.typ) {
intro = " of parameterized type "
} else if tpar = asTypeParam(x.typ); tpar != nil {
intro = " of type parameter "
} else {
intro = " of type "
}
buf.WriteString(intro)
WriteType(&buf, x.typ, qf)
if tpar != nil {
buf.WriteString(" constrained by ")
WriteType(&buf, tpar.bound, qf) // do not compute interface type sets here
}
} else {
buf.WriteString(" with invalid type")
}