Commit dd8f29e3 authored by Russ Cox's avatar Russ Cox

reflect: adjust Value.String to give correct answer for methods

Fixes #7859.

LGTM=r
R=adonovan, r
CC=golang-codereviews
https://golang.org/cl/136710043
parent 2debfeb9
......@@ -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>")
}
}
......@@ -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.
......
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