1
0
mirror of https://github.com/golang/go synced 2024-11-17 10:04:43 -07:00

cmd/compile/internal/types2: implement TypeList.String (debugging support)

Change-Id: Iaa203def3dac94a7d5ff6120e89315c3d7977ee1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345471
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2021-08-26 11:56:52 -07:00
parent c9e05fdcf7
commit 03db2c2413
3 changed files with 14 additions and 7 deletions

View File

@ -75,7 +75,7 @@ func Instantiate(env *Environment, typ Type, targs []Type, validate bool) (Type,
func (check *Checker) instantiate(pos syntax.Pos, typ Type, targs []Type, posList []syntax.Pos) (res Type) {
assert(check != nil)
if check.conf.Trace {
check.trace(pos, "-- instantiating %s with %s", typ, typeListString(targs))
check.trace(pos, "-- instantiating %s with %s", typ, NewTypeList(targs))
check.indent++
defer func() {
check.indent--

View File

@ -281,12 +281,6 @@ func instantiatedHash(typ *Named, targs []Type) string {
return string(res[:i])
}
func typeListString(list []Type) string {
var buf bytes.Buffer
writeTypeList(&buf, list, nil, nil)
return buf.String()
}
// typOrNil is like typ but if the argument is nil it is replaced with Typ[Invalid].
// A nil type may appear in pathological cases such as type T[P any] []func(_ T([]_))
// where an array/slice element is accessed before it is set up.

View File

@ -4,6 +4,8 @@
package types2
import "bytes"
// TParamList holds a list of type parameters.
type TParamList struct{ tparams []*TypeParam }
@ -52,6 +54,17 @@ func (l *TypeList) list() []Type {
return l.types
}
func (l *TypeList) String() string {
if l == nil || len(l.types) == 0 {
return "[]"
}
var buf bytes.Buffer
buf.WriteByte('[')
writeTypeList(&buf, l.types, nil, nil)
buf.WriteByte(']')
return buf.String()
}
// ----------------------------------------------------------------------------
// Implementation