aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzlasd <zlasd@hotmail.com>2022-03-27 21:17:53 +0800
committerIan Lance Taylor <iant@golang.org>2022-04-04 17:27:45 +0000
commitac313524fe4997b80a4221647f0da79d0e07b88e (patch)
treee1c4addaad0193c0ec9b8a2881c3a3c9c3732466
parent35998c010947d3a5a26409fffcb4ed16c3595850 (diff)
downloadgo-ac313524fe4997b80a4221647f0da79d0e07b88e.tar.gz
go-ac313524fe4997b80a4221647f0da79d0e07b88e.zip
reflect: fix Value.NumMethod docs
NumMethod counts unexported methods for interface types. This behavior is documented in Type.NumMethod Fixes #42123 Change-Id: Ia5aba353a8cc64190c701d1521972d57e8903564 Reviewed-on: https://go-review.googlesource.com/c/go/+/396075 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Cherry Mui <cherryyz@google.com>
-rw-r--r--src/reflect/type.go4
-rw-r--r--src/reflect/value.go6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/reflect/type.go b/src/reflect/type.go
index 209a7bae4d..53c17f9e55 100644
--- a/src/reflect/type.go
+++ b/src/reflect/type.go
@@ -72,7 +72,9 @@ type Type interface {
// NumMethod returns the number of methods accessible using Method.
//
- // Note that NumMethod counts unexported methods only for interface types.
+ // For a non-interface type, it returns the number of exported methods.
+ //
+ // For an interface type, it returns the number of exported and unexported methods.
NumMethod() int
// Name returns the type's name within its package for a defined type.
diff --git a/src/reflect/value.go b/src/reflect/value.go
index 8410dfc30a..f1454b8ae2 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -1868,7 +1868,11 @@ func (v Value) Method(i int) Value {
return Value{v.typ, v.ptr, fl}
}
-// NumMethod returns the number of exported methods in the value's method set.
+// NumMethod returns the number of methods in the value's method set.
+//
+// For a non-interface type, it returns the number of exported methods.
+//
+// For an interface type, it returns the number of exported and unexported methods.
func (v Value) NumMethod() int {
if v.typ == nil {
panic(&ValueError{"reflect.Value.NumMethod", Invalid})