From 063b06df42eb21aeb866e9483a691c90e1cd8a6e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 28 Oct 2022 12:58:01 +0000 Subject: [PATCH] Internal change PiperOrigin-RevId: 484509863 --- .../protobuf/compiler/objectivec/map_field.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/map_field.cc b/src/google/protobuf/compiler/objectivec/map_field.cc index 767aa1dbca..f0f40d9a76 100644 --- a/src/google/protobuf/compiler/objectivec/map_field.cc +++ b/src/google/protobuf/compiler/objectivec/map_field.cc @@ -163,20 +163,24 @@ void MapFieldGenerator::DetermineForwardDeclarations( std::set* fwd_decls, bool include_external_types) const { RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls, include_external_types); + const FieldDescriptor* value_descriptor = + descriptor_->message_type()->map_value(); // NOTE: Maps with values of enums don't have to worry about adding the // forward declaration because `GPB*EnumDictionary` isn't generic to the // specific enum (like say `NSDictionary`) and thus doesn't // reference the type in the header. + if (GetObjectiveCType(value_descriptor) != OBJECTIVECTYPE_MESSAGE) { + return; + } + + const Descriptor* value_msg_descriptor = value_descriptor->message_type(); - const FieldDescriptor* value_descriptor = - descriptor_->message_type()->map_value(); // Within a file there is no requirement on the order of the messages, so // local references need a forward declaration. External files (not WKTs), // need one when requested. - if (GetObjectiveCType(value_descriptor) == OBJECTIVECTYPE_MESSAGE && - ((include_external_types && - !IsProtobufLibraryBundledProtoFile(value_descriptor->file())) || - descriptor_->file() == value_descriptor->file())) { + if ((include_external_types && + !IsProtobufLibraryBundledProtoFile(value_msg_descriptor->file())) || + descriptor_->file() == value_msg_descriptor->file()) { const std::string& value_storage_type = value_field_generator_->variable("storage_type"); fwd_decls->insert("@class " + value_storage_type);