Skip to content

protoc-gen-go: unexpected trailing underscore in oneof field name #780

Closed
@zellyn

Description

@zellyn

What version of protobuf and what language are you using?
Version: go1.11.4 darwin/amd64

What did you do?

syntax = "proto2";

package oneoftest;

// If you rename this to `PutBar`, the problem goes away.
message GetBar {
    optional string a_string = 1;
}

message Foo {
  oneof bar {
    GetBar get_bar = 1;
  }
}

What did you expect to see?
The oneof field on the struct should be named Bar, since there's nothing else for it to conflict with.

What did you see instead?
The oneof field is named Bar_.

type Foo struct {
	// Types that are valid to be assigned to Bar_:
	//	*Foo_GetBar
	Bar_                 isFoo_Bar_ `protobuf_oneof:"bar"`
	XXX_NoUnkeyedLiteral struct{}   `json:"-"`
	XXX_unrecognized     []byte     `json:"-"`
	XXX_sizecache        int32      `json:"-"`
}

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment?

IRL, we have things named GetRequest and PutRequest, and oneof fields named Request. I'm trying to upgrade our version of golang/protobuf, and this is causing widespread breakage.

I think it's happening because of the conflict with the GetBar() method on the struct, but the renaming of the field itself was unexpected, and caused breakage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions