diff --git a/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go b/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go index 7754ac0e..fbb7da39 100644 --- a/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go +++ b/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go @@ -59,7 +59,7 @@ func (Enum) EnumDescriptor() ([]byte, []int) { type Message struct { StringField *string `protobuf:"bytes,1,opt,name=string_field,json=stringField" json:"string_field,omitempty"` - EnumField *Enum `protobuf:"varint,2,opt,name=enum_field,json=enumField,enum=Enum" json:"enum_field,omitempty"` + EnumField *Enum `protobuf:"varint,2,opt,name=enum_field,json=enumField,enum=Enum,def=0" json:"enum_field,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -90,6 +90,8 @@ func (m *Message) XXX_DiscardUnknown() { var xxx_messageInfo_Message proto.InternalMessageInfo +const Default_Message_EnumField Enum = Enum_ZERO + func (m *Message) GetStringField() string { if m != nil && m.StringField != nil { return *m.StringField @@ -101,7 +103,7 @@ func (m *Message) GetEnumField() Enum { if m != nil && m.EnumField != nil { return *m.EnumField } - return Enum_ZERO + return Default_Message_EnumField } func init() { @@ -112,13 +114,14 @@ func init() { func init() { proto.RegisterFile("nopackage/nopackage.proto", fileDescriptor_f33a1d5d178c43c9) } var fileDescriptor_f33a1d5d178c43c9 = []byte{ - // 127 bytes of a gzipped FileDescriptorProto + // 130 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xcb, 0x2f, 0x48, - 0x4c, 0xce, 0x4e, 0x4c, 0x4f, 0xd5, 0x87, 0xb3, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0x82, + 0x4c, 0xce, 0x4e, 0x4c, 0x4f, 0xd5, 0x87, 0xb3, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x95, 0x22, 0xb8, 0xd8, 0x7d, 0x53, 0x8b, 0x8b, 0x13, 0xd3, 0x53, 0x85, 0x14, 0xb9, 0x78, 0x8a, 0x4b, 0x8a, 0x32, 0xf3, 0xd2, 0xe3, 0xd3, 0x32, 0x53, 0x73, 0x52, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, - 0xb8, 0x21, 0x62, 0x6e, 0x20, 0x21, 0x21, 0x15, 0x2e, 0xae, 0xd4, 0xbc, 0xd2, 0x5c, 0xa8, 0x02, - 0x26, 0x05, 0x46, 0x0d, 0x3e, 0x23, 0x56, 0x3d, 0xd7, 0xbc, 0xd2, 0xdc, 0x20, 0x4e, 0x90, 0x04, - 0x58, 0x95, 0x96, 0x00, 0x17, 0x0b, 0x48, 0x48, 0x88, 0x83, 0x8b, 0x25, 0xca, 0x35, 0xc8, 0x5f, - 0x80, 0x01, 0x10, 0x00, 0x00, 0xff, 0xff, 0xb2, 0xbc, 0x78, 0x1f, 0x81, 0x00, 0x00, 0x00, + 0xb8, 0x21, 0x62, 0x6e, 0x20, 0x21, 0x21, 0x2d, 0x2e, 0xae, 0xd4, 0xbc, 0xd2, 0x5c, 0xa8, 0x02, + 0x26, 0x05, 0x46, 0x0d, 0x3e, 0x23, 0x56, 0x3d, 0xd7, 0xbc, 0xd2, 0x5c, 0x2b, 0x96, 0x28, 0xd7, + 0x20, 0xff, 0x20, 0x4e, 0x90, 0x34, 0x58, 0xad, 0x96, 0x00, 0x17, 0x0b, 0x48, 0x42, 0x88, 0x83, + 0x0b, 0x2c, 0x25, 0xc0, 0x00, 0x08, 0x00, 0x00, 0xff, 0xff, 0x31, 0x29, 0xe4, 0xb2, 0x87, 0x00, + 0x00, 0x00, } diff --git a/cmd/protoc-gen-go/testdata/nopackage/nopackage.proto b/cmd/protoc-gen-go/testdata/nopackage/nopackage.proto index e2f2f969..892bb066 100644 --- a/cmd/protoc-gen-go/testdata/nopackage/nopackage.proto +++ b/cmd/protoc-gen-go/testdata/nopackage/nopackage.proto @@ -12,5 +12,5 @@ enum Enum { message Message { optional string string_field = 1; - optional Enum enum_field = 2; + optional Enum enum_field = 2 [default=ZERO]; } diff --git a/reflect/prototype/protofile_type.go b/reflect/prototype/protofile_type.go index 99f3be91..66e8a622 100644 --- a/reflect/prototype/protofile_type.go +++ b/reflect/prototype/protofile_type.go @@ -544,6 +544,8 @@ func resolveReference(parent pref.Descriptor, refName pref.FullName) pref.Descri } else if refName[len(curName)] == '.' { refName = refName[len(curName)+len("."):] break // e.g., refName: foo.firetruck.driver, curName: foo.firetruck + } else if len(curName) == 0 { + break // FileDescriptor has no package name } // No match. (e.g., refName: foo.firetruck, curName: foo.fire) }