Commit ce304585 authored by Matthew Dempsky's avatar Matthew Dempsky Committed by Robert Griesemer

go/types: fix TypeString(nil, nil)

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 <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent 7832c82b
......@@ -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) {
......@@ -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) {
......
......@@ -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"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment