Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
reflect: NumMethod includes non-exported methods for interface types #22075
Type.Method's docs say:
Value.Method's docs say:
But this program demonstrates that they both include the number of non-exported methods when applied to interface types: https://play.golang.org/p/Drv0u6n9bg
According to the documentation, it should print "0 0", but instead it prints "1 1".
@mdempsky I see multiple potential solutions:
@mvdan Assuming the NumMethods documentation is correct and the implementation is just wrong for interfaces, then those solutions sound reasonable.
I wanted some of the reflect API experts to weigh in first on whether the code needs to be fixed, or the document just needs to be updated.
@mvdan For what it's worth, my 2c is we should fix the code to match the current documentation. The main hesitation in my mind is just whether users are inadvertently relying on the current behavior.
If you want to speculatively work on a fix, that might also help answer the question of whether users depend on the current behavior or not.
As for recommended fix, I'm not sure we need
I think uncommontype and interfacetype will need to keep separate exportedMethods code, because the former returns