Skip to content

Commit

Permalink
Cherry-pick the fix for protocolbuffers#7463.
Browse files Browse the repository at this point in the history
  • Loading branch information
haberman committed May 12, 2020
1 parent 3c3646f commit c0b1ce0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/google/protobuf/generated_message_reflection.cc
Expand Up @@ -1061,7 +1061,7 @@ void Reflection::ListFields(const Message& message,
if (oneof_case_array[containing_oneof->index()] == field->number()) {
output->push_back(field);
}
} else if (has_bits) {
} else if (has_bits && has_bits_indices[i] != -1) {
// Equivalent to: HasBit(message, field)
if (IsIndexInHasBitSet(has_bits, has_bits_indices[i])) {
output->push_back(field);
Expand Down
12 changes: 9 additions & 3 deletions src/google/protobuf/proto3_arena_unittest.cc
Expand Up @@ -217,9 +217,15 @@ TEST(Proto3OptionalTest, OptionalFieldDescriptor) {

for (int i = 0; i < d->field_count(); i++) {
const FieldDescriptor* f = d->field(i);
EXPECT_TRUE(f->has_optional_keyword()) << f->full_name();
EXPECT_TRUE(f->has_presence()) << f->full_name();
EXPECT_TRUE(f->containing_oneof()) << f->full_name();
if (HasPrefixString(f->name(), "singular")) {
EXPECT_FALSE(f->has_optional_keyword()) << f->full_name();
EXPECT_FALSE(f->has_presence()) << f->full_name();
EXPECT_FALSE(f->containing_oneof()) << f->full_name();
} else {
EXPECT_TRUE(f->has_optional_keyword()) << f->full_name();
EXPECT_TRUE(f->has_presence()) << f->full_name();
EXPECT_TRUE(f->containing_oneof()) << f->full_name();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/google/protobuf/unittest_proto3_optional.proto
Expand Up @@ -72,4 +72,8 @@ message TestProto3Optional {
optional NestedMessage optional_nested_message = 18;
optional NestedMessage lazy_nested_message = 19 [lazy = true];
optional NestedEnum optional_nested_enum = 21;

// Add some non-optional fields to verify we can mix them.
int32 singular_int32 = 22;
int64 singular_int64 = 23;
}

0 comments on commit c0b1ce0

Please sign in to comment.