Makes extension declaration field name and type optional if `reserved: true` is present. Revert the support of declaration with only number is set; this used to indicate that a number is already in use by multiple extensions.

PiperOrigin-RevId: 524115436
pull/12466/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 02380874f7
commit 21256b86a9
  1. 23
      src/google/protobuf/descriptor.cc

@ -6626,10 +6626,6 @@ void DescriptorBuilder::CheckExtensionDeclaration(
const FieldDescriptor& field, const FieldDescriptorProto& proto, const FieldDescriptor& field, const FieldDescriptorProto& proto,
absl::string_view declared_full_name, absl::string_view declared_type_name, absl::string_view declared_full_name, absl::string_view declared_type_name,
bool is_repeated) { bool is_repeated) {
if (declared_type_name.empty() && declared_full_name.empty()) {
return;
}
if (!declared_full_name.empty()) { if (!declared_full_name.empty()) {
std::string actual_full_name = absl::StrCat(".", field.full_name()); std::string actual_full_name = absl::StrCat(".", field.full_name());
@ -7459,12 +7455,19 @@ void DescriptorBuilder::ValidateExtensionDeclaration(
}); });
} }
if (declaration.has_full_name() != declaration.has_type()) { // Both full_name and type should be present. If none of them is set,
AddError(full_name, proto, DescriptorPool::ErrorCollector::EXTENDEE, [&] { // add an error unless reserved is set to true. If only one of them is set,
return absl::StrCat( // add an error whether or not reserved is set to true.
"Extension declaration #", declaration.number(), if (!declaration.has_full_name() || !declaration.has_type()) {
" should have both \"full_name\" and \"type\" set."); if (declaration.has_full_name() != declaration.has_type() ||
}); !declaration.reserved()) {
AddError(full_name, proto, DescriptorPool::ErrorCollector::EXTENDEE,
[&] {
return absl::StrCat(
"Extension declaration #", declaration.number(),
" should have both \"full_name\" and \"type\" set.");
});
}
} else { } else {
if (!full_name_set.insert(declaration.full_name()).second) { if (!full_name_set.insert(declaration.full_name()).second) {
AddError( AddError(

Loading…
Cancel
Save