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

Closed
mvdan opened this issue Jan 21, 2022 · 3 comments
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 21, 2022
@ianlancetaylor
Copy link
Contributor

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 The path to resolution is known, but the work has not been done. labels Jan 21, 2022
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 21, 2022
@cuonglm
Copy link
Member

cuonglm commented Jan 22, 2022

@dsnet
Copy link
Member

dsnet commented Aug 26, 2022

@dsnet dsnet closed this as completed Aug 26, 2022
@golang golang locked and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants