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
Conversation
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.
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.
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:
- a .proto file, like the one you listed in Generated code will not compile if the service defined in protobuf definition has a method defined with the same name. #123.
- a
gen.go
file like the one used by theproto
test which tellsgo generate
to make code. - a
_test.go
file like the one used by theproto
test which has a test case that passes if the package compiles.
Finally, please run make test_all
to regenerate code and run the tests.
Thanks for reporting and fixing this bug!
Sorry I missed the tests when I looked quickly. I've now added a test for compilation. |
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, 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.
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? |
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, 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!
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.