From: Rob Findley Date: Wed, 4 Aug 2021 01:39:53 +0000 (-0400) Subject: [dev.typeparams] go/types: print constraint info for type param operands X-Git-Tag: go1.18beta1~1818^2^2~46 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b01e775e9c05dd2e5fa19ea06ac09f9a12ae660e;p=gostls13.git [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 Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/go/types/operand.go b/src/go/types/operand.go index c605cf781c..aea8bf5e7a 100644 --- a/src/go/types/operand.go +++ b/src/go/types/operand.go @@ -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") }