From 309c50e8f399b20e8dd89f6925d02ecf38271284 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 14 Mar 2023 16:33:56 -0700 Subject: [PATCH] Internal Code Change PiperOrigin-RevId: 516665926 --- src/google/protobuf/BUILD.bazel | 3 +++ src/google/protobuf/compiler/java/BUILD.bazel | 2 ++ src/google/protobuf/compiler/java/helpers.cc | 6 +++++ src/google/protobuf/compiler/java/helpers.h | 9 ++++---- .../protobuf/compiler/java/message_field.cc | 3 ++- .../compiler/java/message_field_lite.cc | 3 ++- .../protobuf/compiler/java/message_lite.cc | 4 +++- src/google/protobuf/descriptor.cc | 14 +++++++---- src/google/protobuf/descriptor.h | 1 + src/google/protobuf/descriptor_unittest.cc | 6 +++-- src/google/protobuf/dynamic_message.cc | 18 ++++++++------- .../protobuf/generated_message_reflection.cc | 23 +++++++++++++------ .../protobuf/generated_message_reflection.h | 3 +-- src/google/protobuf/message.h | 11 ++------- src/google/protobuf/proto3_arena_unittest.cc | 13 +++++++---- 15 files changed, 73 insertions(+), 46 deletions(-) diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index d76201d8f1..6bdaefb266 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -403,6 +403,7 @@ cc_library( "descriptor.h", "descriptor.pb.h", "descriptor_database.h", + "descriptor_legacy.h", "dynamic_message.h", "field_access_listener.h", "generated_enum_reflection.h", @@ -898,6 +899,7 @@ cc_test( }), deps = [ ":cc_test_protos", + ":descriptor_legacy", ":protobuf", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/testing", @@ -1147,6 +1149,7 @@ cc_test( }), deps = [ ":cc_test_protos", + ":descriptor_legacy", ":protobuf", ":test_util", "//src/google/protobuf/stubs", diff --git a/src/google/protobuf/compiler/java/BUILD.bazel b/src/google/protobuf/compiler/java/BUILD.bazel index 74c801e4c4..94573892c4 100644 --- a/src/google/protobuf/compiler/java/BUILD.bazel +++ b/src/google/protobuf/compiler/java/BUILD.bazel @@ -35,6 +35,7 @@ cc_library( include_prefix = "google/protobuf/compiler/java", visibility = ["//pkg:__pkg__"], deps = [ + "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", "@com_google_absl//absl/container:flat_hash_set", @@ -112,6 +113,7 @@ cc_library( deps = [ ":names", ":names_internal", + "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index eef40ee3ba..efbdcf7ba6 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -52,6 +52,7 @@ #include "absl/strings/substitute.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/strtod.h" #include "google/protobuf/wire_format.h" @@ -832,6 +833,11 @@ bool HasRequiredFields(const Descriptor* type) { return HasRequiredFields(type, &already_seen); } +bool IsRealOneof(const FieldDescriptor* descriptor) { + return descriptor->containing_oneof() && + !OneofDescriptorLegacy(descriptor->containing_oneof()).is_synthetic(); +} + bool HasRepeatedFields(const Descriptor* descriptor) { for (int i = 0; i < descriptor->field_count(); ++i) { const FieldDescriptor* field = descriptor->field(i); diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index 7cd37e0e1d..66d08d5123 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -43,6 +43,7 @@ #include "google/protobuf/compiler/java/options.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" // Must be last. @@ -354,10 +355,7 @@ inline bool HasPackedFields(const Descriptor* descriptor) { // them has a required field. Return true if a required field is found. bool HasRequiredFields(const Descriptor* descriptor); -inline bool IsRealOneof(const FieldDescriptor* descriptor) { - return descriptor->containing_oneof() && - !descriptor->containing_oneof()->is_synthetic(); -} +bool IsRealOneof(const FieldDescriptor* descriptor); inline bool HasHasbit(const FieldDescriptor* descriptor) { return internal::cpp::HasHasbit(descriptor); @@ -366,7 +364,8 @@ inline bool HasHasbit(const FieldDescriptor* descriptor) { // Whether generate classes expose public PARSER instances. inline bool ExposePublicParser(const FileDescriptor* descriptor) { // TODO(liujisi): Mark the PARSER private in 3.1.x releases. - return descriptor->syntax() == FileDescriptor::SYNTAX_PROTO2; + return FileDescriptorLegacy(descriptor).syntax() == + FileDescriptorLegacy::Syntax::SYNTAX_PROTO2; } // Whether unknown enum values are kept (i.e., not stored in UnknownFieldSet diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index 5fd8b6678d..00fdba80d1 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -42,6 +42,7 @@ #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" @@ -414,7 +415,7 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( } void ImmutableMessageFieldGenerator::GenerateKotlinOrNull(io::Printer* printer) const { - if (descriptor_->has_optional_keyword()) { + if (FieldDescriptorLegacy(descriptor_).has_optional_keyword()) { printer->Print(variables_, "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" " get() = $kt_dsl_builder$.$name$OrNull\n"); diff --git a/src/google/protobuf/compiler/java/message_field_lite.cc b/src/google/protobuf/compiler/java/message_field_lite.cc index 148f844936..b742dc8025 100644 --- a/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/src/google/protobuf/compiler/java/message_field_lite.cc @@ -42,6 +42,7 @@ #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" #include "google/protobuf/compiler/java/name_resolver.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" @@ -325,7 +326,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( } void ImmutableMessageFieldLiteGenerator::GenerateKotlinOrNull(io::Printer* printer) const { - if (descriptor_->has_optional_keyword()) { + if (FieldDescriptorLegacy(descriptor_).has_optional_keyword()) { printer->Print(variables_, "public val $classname$Kt.Dsl.$name$OrNull: $kt_type$?\n" " get() = $kt_dsl_builder$.$name$OrNull\n"); diff --git a/src/google/protobuf/compiler/java/message_lite.cc b/src/google/protobuf/compiler/java/message_lite.cc index b23f0e0101..6fbbdb8dc6 100644 --- a/src/google/protobuf/compiler/java/message_lite.cc +++ b/src/google/protobuf/compiler/java/message_lite.cc @@ -54,6 +54,7 @@ #include "google/protobuf/compiler/java/message_builder_lite.h" #include "google/protobuf/compiler/java/name_resolver.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" @@ -507,7 +508,8 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuildMessageInfo( std::vector chars; int flags = 0; - if (descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO2) { + if (FileDescriptorLegacy(descriptor_->file()).syntax() == + FileDescriptorLegacy::Syntax::SYNTAX_PROTO2) { flags |= 0x1; } if (descriptor_->options().message_set_wire_format()) { diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 329d779280..fd7e914096 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -71,6 +71,7 @@ #include "google/protobuf/any.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor_database.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/generated_message_util.h" #include "google/protobuf/io/strtod.h" @@ -4871,10 +4872,11 @@ PROTOBUF_NOINLINE static bool ExistingFileMatchesProto( existing_file->CopyTo(&existing_proto); // TODO(liujisi): Remove it when CopyTo supports copying syntax params when // syntax="proto2". - if (existing_file->syntax() == FileDescriptor::SYNTAX_PROTO2 && + if (FileDescriptorLegacy(existing_file).syntax() == + FileDescriptorLegacy::Syntax::SYNTAX_PROTO2 && proto.has_syntax()) { - existing_proto.set_syntax( - existing_file->SyntaxName(existing_file->syntax())); + existing_proto.set_syntax(FileDescriptorLegacy::SyntaxName( + FileDescriptorLegacy(existing_file).syntax())); } return existing_proto.SerializeAsString() == proto.SerializeAsString(); @@ -8435,7 +8437,8 @@ bool HasHasbit(const FieldDescriptor* field) { // message fields a hasbit only if "optional" is present. If the user is // explicitly writing "optional", it is likely they are writing it on // primitive fields also. - return (field->has_optional_keyword() || field->is_required()) && + return (FieldDescriptorLegacy(field).has_optional_keyword() || + field->is_required()) && !field->options().weak(); } @@ -8449,7 +8452,8 @@ static bool FileUtf8Verification(const FileDescriptor* file) { // Which level of UTF-8 enforcemant is placed on this file. Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, bool is_lite) { - if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 && + if (FileDescriptorLegacy(field->file()).syntax() == + FileDescriptorLegacy::Syntax::SYNTAX_PROTO3 && FieldEnforceUtf8(field)) { return Utf8CheckMode::kStrict; } else if (!is_lite && FileUtf8Verification(field->file())) { diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 4a4462aa04..0721749645 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -1105,6 +1105,7 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase { OneofDescriptor() {} friend class DescriptorBuilder; friend class Descriptor; + friend class FieldDescriptor; }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(OneofDescriptor, 40); diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index c4c7e933c0..b692b0ce13 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -48,6 +48,7 @@ #include "absl/log/scoped_mock_log.h" #include "absl/strings/str_format.h" #include "absl/strings/string_view.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_custom_options.pb.h" #include "google/protobuf/stubs/common.h" @@ -540,7 +541,7 @@ TEST_F(FileDescriptorTest, Syntax) { DescriptorPool pool; const FileDescriptor* file = pool.BuildFile(proto); EXPECT_TRUE(file != nullptr); - EXPECT_EQ(FileDescriptor::SYNTAX_PROTO2, file->syntax()); + EXPECT_EQ(FileDescriptorLegacy::Syntax::SYNTAX_PROTO2, FileDescriptorLegacy(file).syntax()); FileDescriptorProto other; file->CopyTo(&other); EXPECT_EQ("proto2", other.syntax()); @@ -551,7 +552,8 @@ TEST_F(FileDescriptorTest, Syntax) { DescriptorPool pool; const FileDescriptor* file = pool.BuildFile(proto); EXPECT_TRUE(file != nullptr); - EXPECT_EQ(FileDescriptor::SYNTAX_PROTO3, file->syntax()); + EXPECT_EQ(FileDescriptorLegacy::Syntax::SYNTAX_PROTO3, + FileDescriptorLegacy(file).syntax()); FileDescriptorProto other; file->CopyTo(&other); EXPECT_EQ("proto3", other.syntax()); diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc index 16bebfd815..ca3c4a802c 100644 --- a/src/google/protobuf/dynamic_message.cc +++ b/src/google/protobuf/dynamic_message.cc @@ -69,18 +69,19 @@ #include #include +#include "google/protobuf/arenastring.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor_legacy.h" +#include "google/protobuf/extension_set.h" #include "google/protobuf/generated_message_reflection.h" #include "google/protobuf/generated_message_util.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/extension_set.h" #include "google/protobuf/map_field.h" #include "google/protobuf/map_field_inl.h" #include "google/protobuf/map_type_handler.h" #include "google/protobuf/reflection_ops.h" #include "google/protobuf/repeated_field.h" +#include "google/protobuf/unknown_field_set.h" #include "google/protobuf/wire_format.h" @@ -107,7 +108,7 @@ bool IsMapFieldInApi(const FieldDescriptor* field) { return field->is_map(); } inline bool InRealOneof(const FieldDescriptor* field) { return field->containing_oneof() && - !field->containing_oneof()->is_synthetic(); + !OneofDescriptorLegacy(field->containing_oneof()).is_synthetic(); } // Compute the byte size of the in-memory representation of the field. @@ -369,7 +370,8 @@ void DynamicMessage::SharedCtor(bool lock_factory) { // Initialize oneof cases. int oneof_count = 0; for (int i = 0; i < descriptor->oneof_decl_count(); ++i) { - if (descriptor->oneof_decl(i)->is_synthetic()) continue; + if (OneofDescriptorLegacy(descriptor->oneof_decl(i)).is_synthetic()) + continue; new (MutableOneofCaseRaw(oneof_count++)) uint32_t{0}; } @@ -684,7 +686,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( // or not that field is set. int real_oneof_count = 0; for (int i = 0; i < type->oneof_decl_count(); i++) { - if (!type->oneof_decl(i)->is_synthetic()) { + if (!OneofDescriptorLegacy(type->oneof_decl(i)).is_synthetic()) { real_oneof_count++; } } @@ -758,7 +760,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( // The oneofs. for (int i = 0; i < type->oneof_decl_count(); i++) { - if (!type->oneof_decl(i)->is_synthetic()) { + if (!OneofDescriptorLegacy(type->oneof_decl(i)).is_synthetic()) { size = AlignTo(size, kSafeAlignment); offsets[type->field_count() + i] = size; size += kMaxOneofUnionSize; @@ -776,7 +778,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( // Compute the size of default oneof instance and offsets of default // oneof fields. for (int i = 0; i < type->oneof_decl_count(); i++) { - if (type->oneof_decl(i)->is_synthetic()) continue; + if (OneofDescriptorLegacy(type->oneof_decl(i)).is_synthetic()) continue; for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) { const FieldDescriptor* field = type->oneof_decl(i)->field(j); // oneof fields are not accessed through offsets, but we still have the diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 176be5dfd1..26f2fbd18c 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -50,6 +50,7 @@ #include "absl/synchronization/mutex.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/extension_set.h" #include "google/protobuf/generated_message_tctable_gen.h" #include "google/protobuf/generated_message_tctable_impl.h" @@ -957,7 +958,7 @@ void Reflection::SwapOneofField(Message* lhs, Message* rhs, const FieldDescriptor* field; }; - ABSL_DCHECK(!oneof_descriptor->is_synthetic()); + ABSL_DCHECK(!OneofDescriptorLegacy(oneof_descriptor).is_synthetic()); uint32_t oneof_case_lhs = GetOneofCase(*lhs, oneof_descriptor); uint32_t oneof_case_rhs = GetOneofCase(*rhs, oneof_descriptor); @@ -1181,7 +1182,7 @@ void Reflection::InternalSwap(Message* lhs, Message* rhs) const { const int oneof_decl_count = descriptor_->oneof_decl_count(); for (int i = 0; i < oneof_decl_count; i++) { const OneofDescriptor* oneof = descriptor_->oneof_decl(i); - if (!oneof->is_synthetic()) { + if (!OneofDescriptorLegacy(oneof).is_synthetic()) { SwapOneofField(lhs, rhs, oneof); } } @@ -2399,7 +2400,7 @@ const void* Reflection::GetRawRepeatedField(const Message& message, const FieldDescriptor* Reflection::GetOneofFieldDescriptor( const Message& message, const OneofDescriptor* oneof_descriptor) const { - if (oneof_descriptor->is_synthetic()) { + if (OneofDescriptorLegacy(oneof_descriptor).is_synthetic()) { const FieldDescriptor* field = oneof_descriptor->field(0); return HasField(message, field) ? field : nullptr; } @@ -2482,7 +2483,8 @@ const FieldDescriptor* Reflection::FindKnownExtensionByNumber( } bool Reflection::SupportsUnknownEnumValues() const { - return descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3; + return FileDescriptorLegacy(descriptor_->file()).syntax() == + FileDescriptorLegacy::Syntax::SYNTAX_PROTO3; } // =================================================================== @@ -2548,9 +2550,16 @@ uint32_t* Reflection::MutableHasBits(Message* message) const { return GetPointerAtOffset(message, schema_.HasBitsOffset()); } +uint32_t Reflection::GetOneofCase( + const Message& message, const OneofDescriptor* oneof_descriptor) const { + ABSL_DCHECK(!OneofDescriptorLegacy(oneof_descriptor).is_synthetic()); + return internal::GetConstRefAtOffset( + message, schema_.GetOneofCaseOffset(oneof_descriptor)); +} + uint32_t* Reflection::MutableOneofCase( Message* message, const OneofDescriptor* oneof_descriptor) const { - ABSL_DCHECK(!oneof_descriptor->is_synthetic()); + ABSL_DCHECK(!OneofDescriptorLegacy(oneof_descriptor).is_synthetic()); return GetPointerAtOffset( message, schema_.GetOneofCaseOffset(oneof_descriptor)); } @@ -2741,7 +2750,7 @@ void Reflection::SwapBit(Message* message1, Message* message2, bool Reflection::HasOneof(const Message& message, const OneofDescriptor* oneof_descriptor) const { - if (oneof_descriptor->is_synthetic()) { + if (OneofDescriptorLegacy(oneof_descriptor).is_synthetic()) { return HasField(message, oneof_descriptor->field(0)); } return (GetOneofCase(message, oneof_descriptor) > 0); @@ -2761,7 +2770,7 @@ void Reflection::ClearOneofField(Message* message, void Reflection::ClearOneof(Message* message, const OneofDescriptor* oneof_descriptor) const { - if (oneof_descriptor->is_synthetic()) { + if (OneofDescriptorLegacy(oneof_descriptor).is_synthetic()) { ClearField(message, oneof_descriptor->field(0)); return; } diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index 2f18639dbc..e0d87b33aa 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -133,8 +133,7 @@ struct ReflectionSchema { uint32_t GetObjectSize() const { return static_cast(object_size_); } bool InRealOneof(const FieldDescriptor* field) const { - return field->containing_oneof() && - !field->containing_oneof()->is_synthetic(); + return field->real_containing_oneof(); } // Offset of a non-oneof field. Getting a field offset is slightly more diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 645dc3db25..e76cf5666a 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -1191,8 +1191,8 @@ class PROTOBUF_EXPORT Reflection final { inline const uint32_t* GetHasBits(const Message& message) const; inline uint32_t* MutableHasBits(Message* message) const; - inline uint32_t GetOneofCase(const Message& message, - const OneofDescriptor* oneof_descriptor) const; + uint32_t GetOneofCase(const Message& message, + const OneofDescriptor* oneof_descriptor) const; inline uint32_t* MutableOneofCase( Message* message, const OneofDescriptor* oneof_descriptor) const; inline bool HasExtensionSet(const Message& /* message */) const { @@ -1527,13 +1527,6 @@ const Type& Reflection::DefaultRaw(const FieldDescriptor* field) const { return *reinterpret_cast(schema_.GetFieldDefault(field)); } -uint32_t Reflection::GetOneofCase( - const Message& message, const OneofDescriptor* oneof_descriptor) const { - ABSL_DCHECK(!oneof_descriptor->is_synthetic()); - return internal::GetConstRefAtOffset( - message, schema_.GetOneofCaseOffset(oneof_descriptor)); -} - bool Reflection::HasOneofField(const Message& message, const FieldDescriptor* field) const { return (GetOneofCase(message, field->containing_oneof()) == diff --git a/src/google/protobuf/proto3_arena_unittest.cc b/src/google/protobuf/proto3_arena_unittest.cc index db1bf2f187..0f4ed9da3a 100644 --- a/src/google/protobuf/proto3_arena_unittest.cc +++ b/src/google/protobuf/proto3_arena_unittest.cc @@ -36,6 +36,7 @@ #include "google/protobuf/text_format.h" #include #include "absl/strings/match.h" +#include "google/protobuf/descriptor_legacy.h" #include "google/protobuf/test_util.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_proto3_arena.pb.h" @@ -297,11 +298,13 @@ TEST(Proto3OptionalTest, OptionalFieldDescriptor) { for (int i = 0; i < d->field_count(); i++) { const FieldDescriptor* f = d->field(i); if (absl::StartsWith(f->name(), "singular")) { - EXPECT_FALSE(f->has_optional_keyword()) << f->full_name(); + EXPECT_FALSE(FieldDescriptorLegacy(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(FieldDescriptorLegacy(f).has_optional_keyword()) + << f->full_name(); EXPECT_TRUE(f->has_presence()) << f->full_name(); EXPECT_TRUE(f->containing_oneof()) << f->full_name(); } @@ -316,8 +319,8 @@ TEST(Proto3OptionalTest, Extensions) { "protobuf_unittest.Proto3OptionalExtensions.ext_with_optional"); ABSL_CHECK(no_optional); ABSL_CHECK(with_optional); - EXPECT_FALSE(no_optional->has_optional_keyword()); - EXPECT_TRUE(with_optional->has_optional_keyword()); + EXPECT_FALSE(FieldDescriptorLegacy(no_optional).has_optional_keyword()); + EXPECT_TRUE(FieldDescriptorLegacy(with_optional).has_optional_keyword()); const Descriptor* d = protobuf_unittest::Proto3OptionalExtensions::descriptor(); EXPECT_TRUE(d->options().HasExtension( @@ -365,7 +368,7 @@ TEST(Proto3OptionalTest, OptionalFieldReflection) { const google::protobuf::OneofDescriptor* o = d->FindOneofByName("_optional_int32"); ABSL_CHECK(f); ABSL_CHECK(o); - EXPECT_TRUE(o->is_synthetic()); + EXPECT_TRUE(OneofDescriptorLegacy(o).is_synthetic()); EXPECT_FALSE(r->HasField(msg, f)); EXPECT_FALSE(r->HasOneof(msg, o));