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

Add missing functions when running impl twice #20

Open
marcosnils opened this issue Jun 22, 2017 · 3 comments
Open

Add missing functions when running impl twice #20

marcosnils opened this issue Jun 22, 2017 · 3 comments

Comments

@marcosnils
Copy link

It'd be awesome if impl could add the missing methods of an interface to a struct when executed twice. What it currently does is just duplicating all the methods.

If this makes sense I can try to craft a PR.

@josharian
Copy link
Owner

This seems like a reasonable request. (It is a trimmed back version of #2, but trimmed back in all the right ways.)

Suggested approach:

  • Add a -incremental flag, use it to enable this new behavior. Alternatively, add a -all flag to disable the behavior and have incremental on by default.
  • If you can't find an existing type that matches the provided type, pretend it exists and has no methods. In particular, don't emit an error in this case.

There is some subtlety around pointer vs non-pointer receivers. Suppose you call impl with an interface containing methods A() and B(), and you provide T as the type, and *T already has a method B(). Should impl generate func (t T) B() { panic(...) }? If yes, then you'll get a method redeclared error: https://play.golang.org/p/fNIjtt-ISj. If not, T won't satisfy the interface, despite your explicit request that it do so: https://play.golang.org/p/8sp05N9zg-. Or should it return an error, which I try to avoid at all costs?

I'd lead towards the method redeclared approach, on the grounds that it is the most likely to make it obvious to the user what has gone wrong. Thoughts welcomed, though.

@DenLilleMand
Copy link

This is exactly what i need, i suppose it has not been implemented or anything? @marcosnils did you do some work on it, or no?

@timsolov
Copy link

implemented in PR#36
but I didn't add -incremental parameter to save compatibility with current IDE logic.

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

No branches or pull requests

4 participants