From: Robert Griesemer Date: Thu, 18 Feb 2021 05:31:41 +0000 (-0800) Subject: [dev.typeparams] cmd/compile/internal/types: review of typestring.go X-Git-Tag: go1.17beta1~1473^2~11 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d6bdd1aeef;p=gostls13.git [dev.typeparams] cmd/compile/internal/types: review of typestring.go 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 Reviewed-by: Robert Findley --- diff --git a/src/cmd/compile/internal/types2/typestring.go b/src/cmd/compile/internal/types2/typestring.go index 4d778df43f..47b2c259e5 100644 --- a/src/cmd/compile/internal/types2/typestring.go +++ b/src/cmd/compile/internal/types2/typestring.go @@ -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) }