reflect: hide unexported methods that do not satisfy interfaces

Fixes #15673

Change-Id: Ib36d8db3299a93d92665dbde012d52c2c5332ac0
Reviewed-on: https://go-review.googlesource.com/23253
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
David Crawshaw 2016-05-19 13:31:58 -04:00
parent b3bf2e7803
commit be1b930653
2 changed files with 81 additions and 38 deletions

View file

@ -2388,13 +2388,13 @@ type outer struct {
inner
}
func (*inner) m() {}
func (*outer) m() {}
func (*inner) M() {}
func (*outer) M() {}
func TestNestedMethods(t *testing.T) {
typ := TypeOf((*outer)(nil))
if typ.NumMethod() != 1 || typ.Method(0).Func.Pointer() != ValueOf((*outer).m).Pointer() {
t.Errorf("Wrong method table for outer: (m=%p)", (*outer).m)
if typ.NumMethod() != 1 || typ.Method(0).Func.Pointer() != ValueOf((*outer).M).Pointer() {
t.Errorf("Wrong method table for outer: (M=%p)", (*outer).M)
for i := 0; i < typ.NumMethod(); i++ {
m := typ.Method(i)
t.Errorf("\t%d: %s %#x\n", i, m.Name, m.Func.Pointer())
@ -2416,18 +2416,15 @@ var unexpi unexpI = new(unexp)
func TestUnexportedMethods(t *testing.T) {
typ := TypeOf(unexpi)
if got := typ.NumMethod(); got != 1 {
t.Error("NumMethod=%d, want 1 satisfied method", got)
}
if typ.Method(0).Type == nil {
t.Error("missing type for satisfied method 'f'")
}
if !typ.Method(0).Func.IsValid() {
t.Error("missing func for satisfied method 'f'")
}
if typ.Method(1).Type != nil {
t.Error("found type for unsatisfied method 'g'")
}
if typ.Method(1).Func.IsValid() {
t.Error("found func for unsatisfied method 'g'")
}
}
type InnerInt struct {
@ -5187,7 +5184,7 @@ func useStack(n int) {
type Impl struct{}
func (Impl) f() {}
func (Impl) F() {}
func TestValueString(t *testing.T) {
rv := ValueOf(Impl{})