]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types: review of typestring.go
authorRobert Griesemer <gri@golang.org>
Thu, 18 Feb 2021 05:31:41 +0000 (21:31 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 18 Feb 2021 20:47:27 +0000 (20:47 +0000)
The changes between (equivalent, and reviewed) go/types/typestring.go
and typestring.go can be seen by comparing patchset 1 and 3. The actual
change is just removing the "// UNREVIEWED" marker plus an adjustment
to writeTParamList (we now always write type constraints).

Change-Id: Ieb109c17756addc954e1ca0da606fa5b335ff30d
Reviewed-on: https://go-review.googlesource.com/c/go/+/293472
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/typestring.go

index 4d778df43f5788c7f5a78d9b1b70c8df27d6079d..47b2c259e5a39b68a2a344b30a0aec250b3d5d04 100644 (file)
@@ -1,4 +1,3 @@
-// UNREVIEWED
 // Copyright 2013 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
@@ -314,33 +313,16 @@ func writeTypeList(buf *bytes.Buffer, list []Type, qf Qualifier, visited []Type)
 }
 
 func writeTParamList(buf *bytes.Buffer, list []*TypeName, qf Qualifier, visited []Type) {
-       // bound returns the type bound for tname. The result is never nil.
-       bound := func(tname *TypeName) Type {
-               // be careful to avoid crashes in case of inconsistencies
-               if t, _ := tname.typ.(*TypeParam); t != nil && t.bound != nil {
-                       return t.bound
-               }
-               return &emptyInterface
-       }
-
-       // If a single type bound is not the empty interface, we have to write them all.
-       var writeBounds bool
-       for _, p := range list {
-               // bound(p) should be an interface but be careful (it may be invalid)
-               b := asInterface(bound(p))
-               if b != nil && !b.Empty() {
-                       writeBounds = true
-                       break
-               }
-       }
-       writeBounds = true // always write the bounds for new type parameter list syntax
-
        buf.WriteString("[")
        var prev Type
        for i, p := range list {
-               b := bound(p)
+               // TODO(gri) support 'any' sugar here.
+               var b Type = &emptyInterface
+               if t, _ := p.typ.(*TypeParam); t != nil && t.bound != nil {
+                       b = t.bound
+               }
                if i > 0 {
-                       if writeBounds && b != prev {
+                       if b != prev {
                                // type bound changed - write previous one before advancing
                                buf.WriteByte(' ')
                                writeType(buf, prev, qf, visited)
@@ -355,7 +337,7 @@ func writeTParamList(buf *bytes.Buffer, list []*TypeName, qf Qualifier, visited
                        buf.WriteString(p.name)
                }
        }
-       if writeBounds && prev != nil {
+       if prev != nil {
                buf.WriteByte(' ')
                writeType(buf, prev, qf, visited)
        }