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

Fix bug with code generation of service with a method of the same name. #124

Merged
merged 6 commits into from Aug 10, 2018

Conversation

darren-west
Copy link

Issue #123

The generated api.twirp.go file will not compile if a service contains a method with the same name as the services name. This is because the generated code uses an embedded struct.

This fix uses the embedded structs name when making a call to the method.

I can't see any unit tests for the generated code. If I get time and don't need to refactor too much I may add one.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Fix bug with go code generation.

The generated api.twirp.go file will not compile if a service contains a method with the same name as the services name. This is because the generated code uses an embedded struct.

This fix uses the embedded structs name when making a call to the method.
Copy link
Contributor

@spenczar spenczar left a comment

Choose a reason for hiding this comment

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

Good catch, thanks!

Twirp's tests of this sort of thing are inside github.com/twitchtv/twirp/internal/twirptest. It shouldn't be hard to add a test case that follows the patterns in there. You can follow the proto testcase, which tests that a package named "proto" doesn't break:
https://github.com/twitchtv/twirp/tree/master/internal/twirptest/proto

You'll need:

Finally, please run make test_all to regenerate code and run the tests.

Thanks for reporting and fixing this bug!

@darren-west
Copy link
Author

Sorry I missed the tests when I looked quickly.

I've now added a test for compilation.

Copy link
Contributor

@spenczar spenczar left a comment

Choose a reason for hiding this comment

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

Thanks, looks good.

Could you run make test_all (or just make generate) and commit the changes that will occur for all files? It looks like files haven't yet been regenerated with your changes.

@darren-west
Copy link
Author

I've pushed the changes.

The Go generated files look good. There is a small change in the python files though. Not sure if they were out of date?

Copy link
Contributor

@spenczar spenczar left a comment

Choose a reason for hiding this comment

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

Thanks, looks good.

The Python changes are because you have a newer version of protoc than the last person who generated the python code. Unfortunately, it's pretty hard to consistently version that program in our Makefile.

It's not consequential, though. That generated code is only used in some tests, and is never used by clients; their code generation will continue to work even if they don't use the same version of protoc as you have installed.

Thanks for the fix!

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.

None yet

2 participants