summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-18 21:19:18 -0400
committerRuss Cox <rsc@golang.org>2014-09-18 21:19:18 -0400
commit469d7709be1212ab0e149f07fe8b69cf9e731908 (patch)
tree74999a99ceca32f61c8b7a4fa5bc536351d4ecbd /src/reflect
parent3f99a9313b3e979bcfbde1252f34b0a53e9473bb (diff)
downloadgo-469d7709be1212ab0e149f07fe8b69cf9e731908.tar.gz
reflect: adjust Value.String to give correct answer for methods
Fixes issue 7859. LGTM=r R=adonovan, r CC=golang-codereviews https://codereview.appspot.com/136710043
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/all_test.go16
-rw-r--r--src/reflect/value.go2
2 files changed, 17 insertions, 1 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index 4be0e353d..b72c4b176 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -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>")
+ }
+}
diff --git a/src/reflect/value.go b/src/reflect/value.go
index b0dfe840b..12d423f3c 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -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.