]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: adjust Value.String to give correct answer for methods
authorRuss Cox <rsc@golang.org>
Fri, 19 Sep 2014 01:19:18 +0000 (21:19 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 19 Sep 2014 01:19:18 +0000 (21:19 -0400)
Fixes #7859.

LGTM=r
R=adonovan, r
CC=golang-codereviews
https://golang.org/cl/136710043

src/reflect/all_test.go
src/reflect/value.go

index 4be0e353df7cb7e8b763ee5280e3a9ab2bc72673..b72c4b176d5ee805906cfaf0b25a220a10e7d6a7 100644 (file)
@@ -3923,3 +3923,19 @@ func useStack(n int) {
        var b [1024]byte // makes frame about 1KB
        useStack(n - 1 + int(b[99]))
 }
+
+type Impl struct{}
+
+func (Impl) f() {}
+
+func TestValueString(t *testing.T) {
+       rv := ValueOf(Impl{})
+       if rv.String() != "<reflect_test.Impl Value>" {
+               t.Errorf("ValueOf(Impl{}).String() = %q, want %q", rv.String(), "<reflect_test.Impl Value>")
+       }
+
+       method := rv.Method(0)
+       if method.String() != "<func() Value>" {
+               t.Errorf("ValueOf(Impl{}).Method(0).String() = %q, want %q", method.String(), "<func() Value>")
+       }
+}
index b0dfe840b6b6eeb282f99610938bb06be4d85fc4..12d423f3c3e73a4d6cc9bb90f0414af0de0ce838 100644 (file)
@@ -1771,7 +1771,7 @@ func (v Value) String() string {
        }
        // If you call String on a reflect.Value of other type, it's better to
        // print something than to panic. Useful in debugging.
-       return "<" + v.typ.String() + " Value>"
+       return "<" + v.Type().String() + " Value>"
 }
 
 // TryRecv attempts to receive a value from the channel v but will not block.