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. 15
      src/google/protobuf/descriptor.cc

@ -6626,10 +6626,6 @@ void DescriptorBuilder::CheckExtensionDeclaration(
const FieldDescriptor& field, const FieldDescriptorProto& proto,
absl::string_view declared_full_name, absl::string_view declared_type_name,
bool is_repeated) {
if (declared_type_name.empty() && declared_full_name.empty()) {
return;
}
if (!declared_full_name.empty()) {
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()) {
AddError(full_name, proto, DescriptorPool::ErrorCollector::EXTENDEE, [&] {
// Both full_name and type should be present. If none of them is set,
// add an error unless reserved is set to true. If only one of them is set,
// add an error whether or not reserved is set to true.
if (!declaration.has_full_name() || !declaration.has_type()) {
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 {
if (!full_name_set.insert(declaration.full_name()).second) {
AddError(

Loading…
Cancel
Save