diff options
author | Adam Cozzette <acozzette@google.com> | 2016-09-29 14:29:23 -0700 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2016-10-10 11:44:54 -0700 |
commit | 70477613b975e45a2d3bec2d18bae11b8c3a1751 (patch) | |
tree | 67fc33bcace8b28b3459c1a7fac8355dbdf19383 /src/google/protobuf/descriptor.cc | |
parent | 34cdaf4c36cee85765d48a8b857be75014f3a8d0 (diff) |
Do strict enum name checking only for proto3
There seem to already be .proto files out there that have conflicting
enum names, which will not be able to build successfully for some
languages (like C#). To prevent this problem from spreading, let's make
it an error for proto3 but just issue a warning for proto2. This fixes
issue #2179.
Diffstat (limited to 'src/google/protobuf/descriptor.cc')
-rw-r--r-- | src/google/protobuf/descriptor.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 4dccb585..be1e1d69 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -4707,11 +4707,20 @@ void DescriptorBuilder::CheckEnumValueUniqueness( // stripping should de-dup the labels in this case). if (!inserted && insert_result.first->second->name() != value->name() && insert_result.first->second->number() != value->number()) { - AddError(value->full_name(), proto.value(i), - DescriptorPool::ErrorCollector::NAME, - "When enum name is stripped and label is PascalCased (" + - stripped + "), this value label conflicts with " + - values[stripped]->name()); + string error_message = + "When enum name is stripped and label is PascalCased (" + stripped + + "), this value label conflicts with " + values[stripped]->name() + + ". This will make the proto fail to compile for some languages, such " + "as C#."; + // There are proto2 enums out there with conflicting names, so to preserve + // compatibility we issue only a warning for proto2. + if (result->file()->syntax() == FileDescriptor::SYNTAX_PROTO2) { + AddWarning(value->full_name(), proto.value(i), + DescriptorPool::ErrorCollector::NAME, error_message); + } else { + AddError(value->full_name(), proto.value(i), + DescriptorPool::ErrorCollector::NAME, error_message); + } } } } |