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: implement NumMethod and Implements #907

Closed
wants to merge 1 commit into from
Closed

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Feb 19, 2020

These two functions are needed by the encoding/json package.

@niaow niaow added this to the v0.13 milestone Feb 26, 2020
panic("reflect: non-interface type passed to Type.Implements")
}
return u.AssignableTo(t)
if u.NumMethod() == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is subtly incorrect, as an interface can include unexported methods. I am not sure though whether there is an easy way to solve this right now. If you wish to leave this for further work, consider adding a comment about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant: golang/go#22075

Copy link
Member Author

@aykevl aykevl Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this might be a bold thing to do but what if we reverted to the old (incorrect) behavior? It would make the implementation of Implements a lot easier, at least as long as we don't need to fully support it. The limited implementation here should be enough for packages like encoding/json.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By which you mean, the same behavior as Go currently has? I would agree with that, lets implement the same bugs 🤡

Copy link
Member Author

@aykevl aykevl Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the same buggy behavior (to be bug-compatible 😉). Reading the bug report the final decision on whether the docs or the implementation should be fixed does not seem to be made yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this is slightly less trivial than I expected: I discovered that anonymous interface types (like var x interface{ F() }) do not have the correct NumMethod.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the status with this one, @aykevl ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to look into this further, haven't done that yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder that we still need to resolve this. 😸

@niaow niaow modified the milestones: v0.13, v0.14 Apr 13, 2020
@niaow niaow modified the milestones: v0.14, v0.15 Jun 27, 2020
These two functions are needed by the encoding/json package.
@aykevl aykevl force-pushed the reflect-nummethods branch from dd5298f to 55d5f1c Compare January 21, 2021 23:30
@aykevl
Copy link
Member Author

aykevl commented Jan 21, 2021

I have updated this branch to be bug-compatible with Go but now it isn't complete enough for encoding/json, so this will need a bit more work.

@aykevl
Copy link
Member Author

aykevl commented Mar 28, 2021

I have implemented Implements in a slightly different way (at compile time). This PR might still be useful one day, but for now I've solved it in a different way. Closing, for now.

@aykevl aykevl closed this Mar 28, 2021
@deadprogram deadprogram deleted the reflect-nummethods branch January 20, 2022 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants