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

Commits on Oct 22, 2019

  1. plugins: Fix code generation for a conflicting oneof

    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}
    sigaev committed Oct 22, 2019
    Configuration menu
    Copy the full SHA
    3d4f2e5 View commit details
    Browse the repository at this point in the history