mirror of
https://github.com/golang/go
synced 2024-11-23 06:40:05 -07:00
[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 <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
c2314babb8
commit
d6bdd1aeef
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user