]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix Value.NumMethod docs
authorzlasd <zlasd@hotmail.com>
Sun, 27 Mar 2022 13:17:53 +0000 (21:17 +0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 4 Apr 2022 17:27:45 +0000 (17:27 +0000)
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>

src/reflect/type.go
src/reflect/value.go

index 209a7bae4d557f38b77a9b84c2dfcb21b30d7425..53c17f9e552f5e6f027a953570bbdf9cbb7c662f 100644 (file)
@@ -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.
index 8410dfc30a6b3ca5906d8695a46062a03152651b..f1454b8ae22519fb65469121f3f14ed959cb8bf2 100644 (file)
@@ -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})