-
Notifications
You must be signed in to change notification settings - Fork 609
deduplicate methods to allow overlapping methods on embedded interfaces #498
Conversation
The tests are failing since the Any suggestions how to proceed here? |
@codyoss Any thoughts on this PR? |
@codyoss Any chance you could have a look at this PR any time soon? |
@marten-seemann Sorry for the slow response here. I am just catching up after being on a sabbatical. I will get to reviewing in the next day or so. Thanks for your understanding. |
Will need to make an implementation for go1.14+ and <go1.14. You call a method named the same thing that exists in two different files. Once file has a build tag of |
@codyoss The problem is not the compiler version in use. The problem is that the Go version set in An easy solution would be to increase the Go version number in the |
Sorry for the slow response here. If I am understanding you correctly it is the code that consumes mockgen must be 1.14. If this is the case we could define a go.mod file in the given test directory. Would that solve the issue? I would prefer not to drop support for older languages versions if not needed. |
Sorry for not making my point clear. The problem is not the version of the Go compiler here. Please have a look at my example in https://gist.github.com/marten-seemann/ea3b81a175844ce00e2e4f155845b57c. This is perfectly valid code from Go 1.14 on, but it will still fail because the version in
As far as I'm aware, you can't have multiple
May I ask why? Is there any use case for supporting older Go version than the Go project itself (which supports only the last two major versions)? To the best of my knowledge, most Go projects have adopted a similar policy for their own code. |
@codyoss Is there anything I can do to help make progress on this PR? |
@codyoss I added the |
@codyoss I rebased the PR (thank you for getting rid of Travis, GH Actions is so much smoother!), and now all tests are passing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. Would you mind adding the push/pop logic to both check_go_mod.sh
and check_go_generate.sh
? Those go commands there will also only be executed in the current module context. Other than that it looks good to me!
@codyoss Done. Can we get a new release once this PR is merged? Would love to use this feature in quic-go soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for your contribution 🎆 . Sorry for the delays!
I will try to get a release out in the next couple of days. In the meantime you can always pin to head temporarily: |
@codyoss, do you know when you'll be able to make a new release? |
Fixes #497.
Description
This PR deduplicates methods to allow overlapping methods on embedded interfaces (which are valid Go since version 1.14). We're using the fact that if the name of the method matches, the parameters need to match as well (e.g. you can't combine two interfaces that both define a method
sayHello()
, where one signature isfunction sayHello()
and the other one isfunction sayHello() error
).Regarding the implementation: I did consider using a map (
map[method name]*method
) for deduplication, however, this would lead to a non-deterministic order when iterating over this map. I'm therefore deduplicating every time a new method is added to the interface. Clearly, the scaling behavior of this is not ideal for interfaces with a lot of methods.I could use an additional set to keep track of function names, but I figured that most interfaces will have a lot less than 20 or so methods, so the performance difference should be negligible. lmk if you disagree with my choice here.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
Reviewer Notes
Release Notes
deduplicate methods to allow overlapping methods on embedded interfaces