]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: implement TypeList.String (debugging support)
authorRobert Findley <rfindley@google.com>
Tue, 31 Aug 2021 21:04:10 +0000 (17:04 -0400)
committerRobert Findley <rfindley@google.com>
Tue, 31 Aug 2021 22:45:42 +0000 (22:45 +0000)
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>

src/go/types/instantiate.go
src/go/types/subst.go
src/go/types/typelists.go

index 6f0b3571d13cbff242057b580b7afb07acfa0c6f..fe4904f63a74be9c19efb6a7acafb85b300cc212 100644 (file)
@@ -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--
index d3b1cad13a0417d70e51b580bf5f4b1621311ffd..3eea44a72a1ad5f233cb53bef3217f02b281f715 100644 (file)
@@ -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.
index ef8ea1f32b69063b5070f2601d8e65eace957936..fc30139b763ab03f057005bc719ee0af868dceb7 100644 (file)
@@ -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