Ban packed option in editions.

This has been replaced with a feature in edition 2023, and we shouldn't allow both to be specified.

PiperOrigin-RevId: 566450709
pull/14130/head
Mike Kruskal 1 year ago committed by Copybara-Service
parent 748d465a2d
commit 5ba3f03d1f
  1. 7
      src/google/protobuf/descriptor.cc
  2. 28
      src/google/protobuf/descriptor_unittest.cc

@ -7906,6 +7906,13 @@ void DescriptorBuilder::ValidateFieldFeatures(
// Rely on our legacy validation for proto2/proto3 files.
if (IsLegacyFeatureSet(field->features())) return;
// Validate legacy options that have been migrated to features.
if (field->options().has_packed()) {
AddError(field->full_name(), proto, DescriptorPool::ErrorCollector::NAME,
"Field option packed is not allowed under editions. Use the "
"repeated_field_encoding feature to control this behavior.");
}
// Validate fully resolved features.
if (field->has_default_value() &&
field->features().field_presence() == FeatureSet::IMPLICIT) {

@ -7631,7 +7631,7 @@ TEST_F(FeaturesTest, RestoresOptionsRoundTrip) {
label: LABEL_REPEATED
type: TYPE_INT64
options {
packed: true
deprecated: true
features {
[pb.test] { int_field_feature: 9 }
}
@ -7716,7 +7716,7 @@ TEST_F(FeaturesTest, RestoresOptionsRoundTrip) {
[pb.test] { int_message_feature: 3 }
})pb"));
EXPECT_THAT(proto.message_type(0).field(0).options(),
EqualsProto(R"pb(packed: true
EqualsProto(R"pb(deprecated: true
features {
[pb.test] { int_field_feature: 9 }
})pb"));
@ -9160,6 +9160,30 @@ TEST_F(FeaturesTest, FeaturesOutsideEditions) {
"editions.\n");
}
TEST_F(FeaturesTest, InvalidFieldPacked) {
BuildDescriptorMessagesInTestPool();
BuildFileWithErrors(
R"pb(
name: "foo.proto"
syntax: "editions"
edition_enum: EDITION_2023
message_type {
name: "Foo"
field {
name: "bar"
number: 1
label: LABEL_REPEATED
type: TYPE_INT64
options { packed: true }
}
}
)pb",
"foo.proto: Foo.bar: NAME: Field option packed is not allowed under "
"editions. Use the repeated_field_encoding feature to control this "
"behavior.\n");
}
TEST_F(FeaturesTest, InvalidFieldImplicitDefault) {
BuildDescriptorMessagesInTestPool();
BuildFileWithErrors(

Loading…
Cancel
Save