Skip to content

Commit

Permalink
reflect: fix Value.NumMethod docs
Browse files Browse the repository at this point in the history
NumMethod counts unexported methods for interface types. This
behavior is documented in Type.NumMethod

Fixes golang#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]>
  • Loading branch information
zlasd authored and ianlancetaylor committed Apr 4, 2022
1 parent 35998c0 commit ac31352
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/reflect/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit ac31352

Please sign in to comment.