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: documentation on NumMethod is incorrect #24914

Closed
dsnet opened this issue Apr 18, 2018 · 2 comments
Closed

reflect: documentation on NumMethod is incorrect #24914

dsnet opened this issue Apr 18, 2018 · 2 comments
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge

Comments

@dsnet
Copy link
Member

dsnet commented Apr 18, 2018

Consider the following:

type iface interface {
	private()
	Public()
}
t := reflect.TypeOf((*iface)(nil)).Elem()
for i := 0; i < t.NumMethod(); i++ {
	fmt.Println(t.Method(i))
}

This currently prints:

{Public  func() <invalid Value> 0}
{private main func() <invalid Value> 1}

The documented behavior of reflect.Type.NumMethod is:

NumMethod returns the number of exported methods in the value's method set.

However, you can clearly see that private is included as part of the count.

It seems to me that for reflect.Interface, the NumMethod does include unexported methods, while it excludes them for all other kinds.

@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Apr 18, 2018
@dsnet dsnet removed the Documentation Issues describing a change to documentation. label Apr 18, 2018
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Apr 18, 2018
@ALTree
Copy link
Member

ALTree commented Apr 18, 2018

This is #22075.

@dsnet
Copy link
Member Author

dsnet commented Apr 18, 2018

Duplicate indeed. Thank you.

@dsnet dsnet closed this as completed Apr 18, 2018
@golang golang locked and limited conversation to collaborators Apr 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation Issues describing a change to documentation. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

3 participants