]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: %T print <nil> for nil
authorChristopher Wedgwood <cw@f00f.org>
Wed, 28 Apr 2010 20:07:19 +0000 (13:07 -0700)
committerRob Pike <r@golang.org>
Wed, 28 Apr 2010 20:07:19 +0000 (13:07 -0700)
R=r
CC=golang-dev, rsc
https://golang.org/cl/1014043

src/pkg/fmt/fmt_test.go
src/pkg/fmt/print.go

index 54006dff8b4af8005d84e2900e7601a0802db4fe..dd5f2d54501fcf2dc8b8936a0d261e9d277c2ace 100644 (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) {
index c8d9e753a15e8bc5d8839ada8d978b150edb6ea0..fb1c3f707db823bfb0b7c899ca5837016870183e 100644 (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: