Skip to content

Commit ac31352

Browse files
zlasdianlancetaylor
authored andcommitted
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 <[email protected]> Trust: Cherry Mui <[email protected]>
1 parent 35998c0 commit ac31352

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/reflect/type.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ type Type interface {
7272

7373
// NumMethod returns the number of methods accessible using Method.
7474
//
75-
// Note that NumMethod counts unexported methods only for interface types.
75+
// For a non-interface type, it returns the number of exported methods.
76+
//
77+
// For an interface type, it returns the number of exported and unexported methods.
7678
NumMethod() int
7779

7880
// Name returns the type's name within its package for a defined type.

src/reflect/value.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,11 @@ func (v Value) Method(i int) Value {
18681868
return Value{v.typ, v.ptr, fl}
18691869
}
18701870

1871-
// NumMethod returns the number of exported methods in the value's method set.
1871+
// NumMethod returns the number of methods in the value's method set.
1872+
//
1873+
// For a non-interface type, it returns the number of exported methods.
1874+
//
1875+
// For an interface type, it returns the number of exported and unexported methods.
18721876
func (v Value) NumMethod() int {
18731877
if v.typ == nil {
18741878
panic(&ValueError{"reflect.Value.NumMethod", Invalid})

0 commit comments

Comments
 (0)