Commit 1331f8b3 authored by Christopher Wedgwood's avatar Christopher Wedgwood Committed by Rob Pike

fmt: %T print <nil> for nil

R=r
CC=golang-dev, rsc
https://golang.org/cl/1014043
parent 96179629
...@@ -264,6 +264,7 @@ var fmttests = []fmtTest{ ...@@ -264,6 +264,7 @@ var fmttests = []fmtTest{
fmtTest{"%d", "hello", "%d(string=hello)"}, fmtTest{"%d", "hello", "%d(string=hello)"},
fmtTest{"no args", "hello", "no args?(extra string=hello)"}, fmtTest{"no args", "hello", "no args?(extra string=hello)"},
fmtTest{"%s", nil, "%s(<nil>)"}, fmtTest{"%s", nil, "%s(<nil>)"},
fmtTest{"%T", nil, "<nil>"},
} }
func TestSprintf(t *testing.T) { func TestSprintf(t *testing.T) {
......
...@@ -1030,6 +1030,10 @@ func (p *pp) doprintf(format string, a []interface{}) { ...@@ -1030,6 +1030,10 @@ func (p *pp) doprintf(format string, a []interface{}) {
// the value's type // the value's type
case 'T': case 'T':
if field == nil {
p.buf.Write(nilAngleBytes)
break
}
p.buf.WriteString(reflect.Typeof(field).String()) p.buf.WriteString(reflect.Typeof(field).String())
default: default:
......
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