mirror of
https://github.com/golang/go
synced 2024-11-11 23:10:23 -07:00
go/types: implement TypeList.String (debugging support)
This is a port of CL 345471 to go/types. Change-Id: Icad5fb8b3b4375182f420a51c80607b88696561e Reviewed-on: https://go-review.googlesource.com/c/go/+/346552 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
580987cd58
commit
5e9ba0b1bd
@ -69,7 +69,7 @@ func Instantiate(env *Environment, typ Type, targs []Type, validate bool) (Type,
|
||||
func (check *Checker) instantiate(pos token.Pos, typ Type, targs []Type, posList []token.Pos) (res Type) {
|
||||
assert(check != nil)
|
||||
if 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--
|
||||
|
@ -284,12 +284,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.
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
package types
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user