Merge pull request #527 from haberman/fix-proto3-enum

Fix for proto2 files that use proto3 enums.
pull/13171/head
Joshua Haberman 3 years ago committed by GitHub
commit 2effcce774
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      upb/def.c
  2. 4
      upb/util/def_to_proto_regular_import_test.proto
  3. 1
      upb/util/def_to_proto_test.proto
  4. 6
      upbc/protoc-gen-upb.cc

@ -1555,7 +1555,7 @@ static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) {
field->submsg_index = sublayout_count++; field->submsg_index = sublayout_count++;
subs[field->submsg_index].submsg = upb_FieldDef_MessageSubDef(f)->layout; subs[field->submsg_index].submsg = upb_FieldDef_MessageSubDef(f)->layout;
} else if (upb_FieldDef_CType(f) == kUpb_CType_Enum && } else if (upb_FieldDef_CType(f) == kUpb_CType_Enum &&
f->file->syntax == kUpb_Syntax_Proto2) { f->sub.enumdef->file->syntax == kUpb_Syntax_Proto2) {
field->submsg_index = sublayout_count++; field->submsg_index = sublayout_count++;
subs[field->submsg_index].subenum = upb_FieldDef_EnumSubDef(f)->layout; subs[field->submsg_index].subenum = upb_FieldDef_EnumSubDef(f)->layout;
UPB_ASSERT(subs[field->submsg_index].subenum); UPB_ASSERT(subs[field->submsg_index].subenum);

@ -30,3 +30,7 @@ syntax = "proto3";
package pkg; package pkg;
message RegularImportMessage {} message RegularImportMessage {}
enum Proto3Enum {
PROTO3_ENUM_ZERO = 0;
}

@ -50,6 +50,7 @@ message Message {
} }
optional pkg.RegularImportMessage regular_import_message = 6; optional pkg.RegularImportMessage regular_import_message = 6;
optional pkg.PublicImportMessage public_import_message = 7; optional pkg.PublicImportMessage public_import_message = 7;
optional pkg.Proto3Enum proto3_enum = 8;
extensions 1000 to max; extensions 1000 to max;
extend Message { extend Message {
optional int32 ext = 1000; optional int32 ext = 1000;

@ -935,7 +935,8 @@ SubLayoutArray::SubLayoutArray(const protobuf::Descriptor* message) {
std::vector<const protobuf::FieldDescriptor*> sorted_subenums = std::vector<const protobuf::FieldDescriptor*> sorted_subenums =
SortedSubEnums(message); SortedSubEnums(message);
for (const auto* field : sorted_subenums) { for (const auto* field : sorted_subenums) {
if (field->file()->syntax() != protobuf::FileDescriptor::SYNTAX_PROTO2) { if (field->enum_type()->file()->syntax() !=
protobuf::FileDescriptor::SYNTAX_PROTO2) {
continue; continue;
} }
if (!indexes_.try_emplace(field->enum_type(), i).second) { if (!indexes_.try_emplace(field->enum_type(), i).second) {
@ -983,7 +984,8 @@ bool TryFillTableEntry(const protobuf::Descriptor* message,
type = "b1"; type = "b1";
break; break;
case protobuf::FieldDescriptor::TYPE_ENUM: case protobuf::FieldDescriptor::TYPE_ENUM:
if (field->file()->syntax() == protobuf::FileDescriptor::SYNTAX_PROTO2) { if (field->enum_type()->file()->syntax() ==
protobuf::FileDescriptor::SYNTAX_PROTO2) {
// We don't have the means to test proto2 enum fields for valid values. // We don't have the means to test proto2 enum fields for valid values.
return false; return false;
} }

Loading…
Cancel
Save