1
0
mirror of https://github.com/golang/go synced 2024-11-25 03:07:56 -07:00

fmt: %T print <nil> for nil

R=r
CC=golang-dev, rsc
https://golang.org/cl/1014043
This commit is contained in:
Christopher Wedgwood 2010-04-28 13:07:19 -07:00 committed by Rob Pike
parent 96179629ef
commit 1331f8b3cb
2 changed files with 5 additions and 0 deletions

View File

@ -264,6 +264,7 @@ var fmttests = []fmtTest{
fmtTest{"%d", "hello", "%d(string=hello)"},
fmtTest{"no args", "hello", "no args?(extra string=hello)"},
fmtTest{"%s", nil, "%s(<nil>)"},
fmtTest{"%T", nil, "<nil>"},
}
func TestSprintf(t *testing.T) {

View File

@ -1030,6 +1030,10 @@ func (p *pp) doprintf(format string, a []interface{}) {
// the value's type
case 'T':
if field == nil {
p.buf.Write(nilAngleBytes)
break
}
p.buf.WriteString(reflect.Typeof(field).String())
default: