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>
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--
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.
package types
+import "bytes"
+
// TParamList holds a list of type parameters.
type TParamList struct{ tparams []*TypeParam }
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