]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: minor cleanup of writeTParamList
authorRobert Findley <rfindley@google.com>
Mon, 16 Aug 2021 01:22:38 +0000 (21:22 -0400)
committerRobert Findley <rfindley@google.com>
Mon, 16 Aug 2021 14:26:59 +0000 (14:26 +0000)
This is a port of CL 339903 to go/types.

Change-Id: Iaf5fe7321d907df4421128c66cf8c58129eaae8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/342435
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/infer.go
src/go/types/typestring.go

index eb0d75e46f222f4b7138f283096b604ae57d2deb..ea1057fe0742b71eaaee469b38ed1c0822a80dc0 100644 (file)
@@ -82,7 +82,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeName, targs []Type,
 
        // Substitute type arguments for their respective type parameters in params,
        // if any. Note that nil targs entries are ignored by check.subst.
-       // TODO(gri) Can we avoid this (we're setting known type argumemts below,
+       // TODO(gri) Can we avoid this (we're setting known type arguments below,
        //           but that doesn't impact the isParameterized check for now).
        if params.Len() > 0 {
                smap := makeSubstMap(tparams, targs)
index 975bba633af17f632e71181c0dad28bd4fba36e9..fa29d75fe2d5a243e3778373204ff4074528f6ce 100644 (file)
@@ -249,23 +249,27 @@ func writeTParamList(buf *bytes.Buffer, list []*TypeName, qf Qualifier, visited
        buf.WriteString("[")
        var prev Type
        for i, p := range list {
-               // TODO(rFindley) support 'any' sugar here.
-               var b Type = &emptyInterface
-               if t, _ := p.typ.(*TypeParam); t != nil && t.bound != nil {
-                       b = t.bound
+               // Determine the type parameter and its constraint.
+               // list is expected to hold type parameter names,
+               // but don't crash if that's not the case.
+               tpar, _ := p.typ.(*TypeParam)
+               var bound Type
+               if tpar != nil {
+                       bound = tpar.bound // should not be nil but we want to see it if it is
                }
+
                if i > 0 {
-                       if b != prev {
-                               // type bound changed - write previous one before advancing
+                       if bound != prev {
+                               // bound changed - write previous one before advancing
                                buf.WriteByte(' ')
                                writeType(buf, prev, qf, visited)
                        }
                        buf.WriteString(", ")
                }
-               prev = b
+               prev = bound
 
-               if t, _ := p.typ.(*TypeParam); t != nil {
-                       writeType(buf, t, qf, visited)
+               if tpar != nil {
+                       writeType(buf, tpar, qf, visited)
                } else {
                        buf.WriteString(p.name)
                }