Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reflect: Value.NumMethod and Type.NumMethod doesn't seem to agree on exported methods #50746

mvdan opened this issue Jan 21, 2022 · 2 comments
Documentation help wanted NeedsFix


Copy link

@mvdan mvdan commented Jan 21, 2022

On e7d5857, I see:

// NumMethod returns the number of exported methods in the value's method set.
func (v Value) NumMethod() int {
    if v.typ == nil {
        panic(&ValueError{"reflect.Value.NumMethod", Invalid})
    if v.flag&flagMethod != 0 {
        return 0
    return v.typ.NumMethod()

Note that Value.NumMethod is documented to only return the number of exported methods. It calls Type.NumMethod, which is documented as:

// NumMethod returns the number of methods accessible using Method.
// Note that NumMethod counts unexported methods only for interface types.

Am I misreading the docs, or do they seem to disagree when it comes to interface types?

cc @dsnet
cc @ianlancetaylor @mdempsky given some past changes regarding NumMethods and exported methods

@mvdan mvdan added the NeedsInvestigation label Jan 21, 2022
Copy link

@ianlancetaylor ianlancetaylor commented Jan 21, 2022

I think you're right and that we should update the documentation for Value.NumMethod.

@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jan 21, 2022
@ianlancetaylor ianlancetaylor added help wanted NeedsFix labels Jan 21, 2022
@gopherbot gopherbot removed the NeedsInvestigation label Jan 21, 2022
Copy link

@cuonglm cuonglm commented Jan 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Documentation help wanted NeedsFix
None yet

No branches or pull requests

5 participants