From ce3045858ae8d37cfc4fade21c0818b408af1c74 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 28 Oct 2015 18:55:30 -0700 Subject: [PATCH] go/types: fix TypeString(nil, nil) The code is meant to return "", 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 TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/go/types/typestring.go | 4 ++-- src/go/types/typestring_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/go/types/typestring.go b/src/go/types/typestring.go index bd62f4dc22..47378e744c 100644 --- a/src/go/types/typestring.go +++ b/src/go/types/typestring.go @@ -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) { diff --git a/src/go/types/typestring_test.go b/src/go/types/typestring_test.go index 913e6c735c..6365df5fe2 100644 --- a/src/go/types/typestring_test.go +++ b/src/go/types/typestring_test.go @@ -148,6 +148,7 @@ func TestQualifiedTypeString(t *testing.T) { this *Package want string }{ + {nil, nil, ""}, {pT, nil, "p.T"}, {pT, p, "T"}, {pT, q, "p.T"}, -- 2.48.1