@@ -991,8 +991,8 @@ bool ContainsProto3Optional(const Descriptor* desc) {
991991 return false ;
992992}
993993
994- bool ContainsProto3Optional (const FileDescriptor* file) {
995- if (file-> edition () == Edition::EDITION_PROTO3) {
994+ bool ContainsProto3Optional (Edition edition, const FileDescriptor* file) {
995+ if (edition == Edition::EDITION_PROTO3) {
996996 for (int i = 0 ; i < file->message_type_count (); i++) {
997997 if (ContainsProto3Optional (file->message_type (i))) {
998998 return true ;
@@ -1600,7 +1600,8 @@ bool CommandLineInterface::ParseInputFiles(
16001600 if (!experimental_editions_ &&
16011601 !absl::StartsWith (parsed_file->name (), " google/protobuf/" ) &&
16021602 !absl::StartsWith (parsed_file->name (), " upb/" )) {
1603- if (parsed_file->edition () >= Edition::EDITION_2023) {
1603+ if (::google::protobuf::internal::InternalFeatureHelper::GetEdition (*parsed_file) >=
1604+ Edition::EDITION_2023) {
16041605 std::cerr
16051606 << parsed_file->name ()
16061607 << " : This file uses editions, but --experimental_editions has not "
@@ -2533,7 +2534,8 @@ bool CommandLineInterface::EnforceProto3OptionalSupport(
25332534 supported_features & CodeGenerator::FEATURE_PROTO3_OPTIONAL;
25342535 if (!supports_proto3_optional) {
25352536 for (const auto fd : parsed_files) {
2536- if (ContainsProto3Optional (fd)) {
2537+ if (ContainsProto3Optional (
2538+ ::google::protobuf::internal::InternalFeatureHelper::GetEdition (*fd), fd)) {
25372539 std::cerr << fd->name ()
25382540 << " : is a proto3 file that contains optional fields, but "
25392541 " code generator "
@@ -2558,7 +2560,9 @@ bool CommandLineInterface::EnforceEditionsSupport(
25582560 return true ;
25592561 }
25602562 for (const auto * fd : parsed_files) {
2561- if (fd->edition () < Edition::EDITION_2023) {
2563+ Edition edition =
2564+ ::google::protobuf::internal::InternalFeatureHelper::GetEdition (*fd);
2565+ if (edition < Edition::EDITION_2023) {
25622566 // Legacy proto2/proto3 files don't need any checks.
25632567 continue ;
25642568 }
@@ -2576,19 +2580,19 @@ bool CommandLineInterface::EnforceEditionsSupport(
25762580 fd->name (), codegen_name);
25772581 return false ;
25782582 }
2579- if (fd-> edition () < minimum_edition) {
2583+ if (edition < minimum_edition) {
25802584 std::cerr << absl::Substitute (
25812585 " $0: is a file using edition $2, which isn't supported by code "
25822586 " generator $1. Please upgrade your file to at least edition $3." ,
2583- fd->name (), codegen_name, fd-> edition () , minimum_edition);
2587+ fd->name (), codegen_name, edition, minimum_edition);
25842588 return false ;
25852589 }
2586- if (fd-> edition () > maximum_edition) {
2590+ if (edition > maximum_edition) {
25872591 std::cerr << absl::Substitute (
25882592 " $0: is a file using edition $2, which isn't supported by code "
25892593 " generator $1. Please ask the owner of this code generator to add "
25902594 " support or switch back to a maximum of edition $3." ,
2591- fd->name (), codegen_name, fd-> edition () , maximum_edition);
2595+ fd->name (), codegen_name, edition, maximum_edition);
25922596 return false ;
25932597 }
25942598 }
0 commit comments