reflect: rtype.MethodByName using binary search

Change-Id: If36e9fd7d6b1993ca2d0d382e7fa52212170c798
Reviewed-on: https://go-review.googlesource.com/c/go/+/425481
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
cuiweixie 2022-08-25 22:08:10 +08:00 committed by Gopher Robot
parent e7312b1005
commit 0053ec452d
2 changed files with 28 additions and 4 deletions

View file

@ -2384,6 +2384,16 @@ func TestMethod(t *testing.T) {
t.Errorf("NoArgs returned %d values; want 0", n)
}
_, ok = TypeOf(&p).MethodByName("AA")
if ok {
t.Errorf(`MethodByName("AA") should have failed`)
}
_, ok = TypeOf(&p).MethodByName("ZZ")
if ok {
t.Errorf(`MethodByName("ZZ") should have failed`)
}
// Curried method of value.
tfunc := TypeOf((func(int) int)(nil))
v := ValueOf(p).Method(1)