Skip to content

Commit

Permalink
go/types: fix TypeString(nil, nil)
Browse files Browse the repository at this point in the history
The code is meant to return "<nil>", but because of a make([]Type, 8)
call that should be make([]Type, 0, 8), the nil Type happens to
already appear in the array.

Change-Id: I2db140046e52f27db1b0ac84bde2b6680677dd95
Reviewed-on: https://go-review.googlesource.com/16464
Run-TryBot: Matthew Dempsky <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
mdempsky authored and griesemer committed Oct 30, 2015
1 parent 7832c82 commit ce30458
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/go/types/typestring.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TypeString(typ Type, qf Qualifier) string {
// The Qualifier controls the printing of
// package-level objects, and may be nil.
func WriteType(buf *bytes.Buffer, typ Type, qf Qualifier) {
writeType(buf, typ, qf, make([]Type, 8))
writeType(buf, typ, qf, make([]Type, 0, 8))
}

func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
Expand Down Expand Up @@ -272,7 +272,7 @@ func writeTuple(buf *bytes.Buffer, tup *Tuple, variadic bool, qf Qualifier, visi
// The Qualifier controls the printing of
// package-level objects, and may be nil.
func WriteSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier) {
writeSignature(buf, sig, qf, make([]Type, 8))
writeSignature(buf, sig, qf, make([]Type, 0, 8))
}

func writeSignature(buf *bytes.Buffer, sig *Signature, qf Qualifier, visited []Type) {
Expand Down
1 change: 1 addition & 0 deletions src/go/types/typestring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func TestQualifiedTypeString(t *testing.T) {
this *Package
want string
}{
{nil, nil, "<nil>"},
{pT, nil, "p.T"},
{pT, p, "T"},
{pT, q, "p.T"},
Expand Down

0 comments on commit ce30458

Please sign in to comment.