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

plugins: Fix code generation for a conflicting oneof #639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sigaev
Copy link

@sigaev sigaev commented Oct 22, 2019

To reproduce the problem that this pull request fixes:

  1. Create file x.proto with the following contents:
syntax = "proto3";
message M {
  oneof b {
    bool a = 1;
    bool get_b = 2;  // Conflicts with "oneof b".
  }
}
  1. Run the following commands:
go get github.com/gogo/protobuf/protoc-gen-gofast
protoc --gofast_out=. --plugin=$HOME/go/bin/protoc-gen-gofast x.proto
grep M_GetB x.pb.go
  1. Output will show that MarshalTo, MarshalToSizedBuffer, Size
    all have an incorrectly named receiver, M_GetB. It needs to be
    M_GetB_ instead:
	//	*M_GetB_
type M_GetB_ struct {
func (*M_GetB_) isM_B() {}
	if x, ok := m.GetB().(*M_GetB_); ok {
		(*M_GetB_)(nil),
func (m *M_GetB) MarshalTo(dAtA []byte) (int, error) {
func (m *M_GetB) MarshalToSizedBuffer(dAtA []byte) (int, error) {
func (m *M_GetB) Size() (n int) {
			m.B = &M_GetB{b}

To reproduce the problem that this pull request fixes:

1. Create x.proto with the following contents:
syntax = "proto3";
message M {
  oneof b {
    bool a = 1;
    bool get_b = 2;  // Conflicts with "oneof b".
  }
}

2. Run the following commands:
go get github.com/gogo/protobuf/protoc-gen-gofast
protoc --gofast_out=. --plugin=$HOME/go/bin/protoc-gen-gofast x.proto
grep M_GetB x.pb.go

3. Output will show that MarshalTo, MarshalToSizedBuffer, Size
   all have an incorrectly named receiver, M_GetB. It needs to be
   M_GetB_ instead:
	//	*M_GetB_
type M_GetB_ struct {
func (*M_GetB_) isM_B() {}
	if x, ok := m.GetB().(*M_GetB_); ok {
		(*M_GetB_)(nil),
func (m *M_GetB) MarshalTo(dAtA []byte) (int, error) {
func (m *M_GetB) MarshalToSizedBuffer(dAtA []byte) (int, error) {
func (m *M_GetB) Size() (n int) {
			m.B = &M_GetB{b}
@jo-asakura
Copy link

Hi @jmarais! Could you help with the PR? It's been an issue for several projects on our side as well.

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.

2 participants