]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: don't panic formatting nil interfaces
authorGustavo Niemeyer <gustavo@niemeyer.net>
Wed, 19 Oct 2011 20:26:08 +0000 (18:26 -0200)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Wed, 19 Oct 2011 20:26:08 +0000 (18:26 -0200)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5296044

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

index 030ad6187fafbd3d90c3c8b743ecd774bdde1745..38280d61f6be3e39951f287dc32101950c1abcda 100644 (file)
@@ -88,6 +88,10 @@ type S struct {
        G G // a struct field that GoStrings
 }
 
+type SI struct {
+       I interface{}
+}
+
 // A type with a String method with pointer receiver for testing %p
 type P int
 
@@ -352,6 +356,7 @@ var fmttests = []struct {
        {"%#v", map[string]int{"a": 1}, `map[string] int{"a":1}`},
        {"%#v", map[string]B{"a": {1, 2}}, `map[string] fmt_test.B{"a":fmt_test.B{I:1, j:2}}`},
        {"%#v", []string{"a", "b"}, `[]string{"a", "b"}`},
+       {"%#v", SI{}, `fmt_test.SI{I:interface { }(nil)}`},
 
        // slices with other formats
        {"%#x", []int{1, 2, 15}, `[0x1 0x2 0xf]`},
index 7721e724115998472f859186982d35569c0a040b..ba50b93283861b87dfc9a4265cab3b057078c2c8 100644 (file)
@@ -842,7 +842,7 @@ BigSwitch:
                value := f.Elem()
                if !value.IsValid() {
                        if goSyntax {
-                               p.buf.WriteString(value.Type().String())
+                               p.buf.WriteString(f.Type().String())
                                p.buf.Write(nilParenBytes)
                        } else {
                                p.buf.Write(nilAngleBytes)