diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/google/protobuf/compiler/js/js_generator.cc | 30 | ||||
-rw-r--r-- | src/google/protobuf/descriptor.cc | 19 | ||||
-rw-r--r-- | src/google/protobuf/descriptor_unittest.cc | 17 |
3 files changed, 43 insertions, 23 deletions
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index fec465fe..58597b4c 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -208,28 +208,28 @@ string GetPath(const GeneratorOptions& options, } } -// Forward declare, so that GetPrefix can call this method, -// which in turn, calls GetPrefix. -string GetPath(const GeneratorOptions& options, - const Descriptor* descriptor); +// Returns the name of the message with a leading dot and taking into account +// nesting, for example ".OuterMessage.InnerMessage", or returns empty if +// descriptor is null. This function does not handle namespacing, only message +// nesting. +string GetNestedMessageName(const Descriptor* descriptor) { + if (descriptor == NULL) { + return ""; + } + return StripPrefixString(descriptor->full_name(), + descriptor->file()->package()); +} // Returns the path prefix for a message or enumeration that // lives under the given file and containing type. string GetPrefix(const GeneratorOptions& options, const FileDescriptor* file_descriptor, const Descriptor* containing_type) { - string prefix = ""; - - if (containing_type == NULL) { - prefix = GetPath(options, file_descriptor); - } else { - prefix = GetPath(options, containing_type); - } - + string prefix = GetPath(options, file_descriptor) + + GetNestedMessageName(containing_type); if (!prefix.empty()) { prefix += "."; } - return prefix; } @@ -277,7 +277,9 @@ string MaybeCrossFileRef(const GeneratorOptions& options, from_file != to_message->file()) { // Cross-file ref in CommonJS needs to use the module alias instead of // the global name. - return ModuleAlias(to_message->file()->name()) + "." + to_message->name(); + return ModuleAlias(to_message->file()->name()) + + GetNestedMessageName(to_message->containing_type()) + + "." + to_message->name(); } else { // Within a single file we use a full name. return GetPath(options, to_message); 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); + } } } } diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 07953416..f6b3f1c5 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -5565,6 +5565,7 @@ TEST_F(ValidationErrorTest, MapEntryConflictsWithEnum) { TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5572,9 +5573,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'BAZ' number: 1 }" "}", "foo.proto: BAZ: NAME: When enum name is stripped and label is " - "PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ\n"); + "PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5582,9 +5585,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { " value { name: 'BAZ' number: 1 }" "}", "foo.proto: BAZ: NAME: When enum name is stripped and label is " - "PascalCased (Baz), this value label conflicts with FOOENUM_BAZ\n"); + "PascalCased (Baz), this value label conflicts with FOOENUM_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5593,9 +5598,11 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR__BAZ: NAME: When enum name is stripped and label is " "PascalCased (BarBaz), this value label conflicts with " - "FOO_ENUM_BAR_BAZ\n"); + "FOO_ENUM_BAR_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); BuildFileWithErrors( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " @@ -5604,11 +5611,13 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR_BAZ: NAME: When enum name is stripped and label is " "PascalCased (BarBaz), this value label conflicts with " - "FOO_ENUM__BAR_BAZ\n"); + "FOO_ENUM__BAR_BAZ. This " + "will make the proto fail to compile for some languages, such as C#.\n"); // This isn't an error because the underscore will cause the PascalCase to // differ by case (BarBaz vs. Barbaz). BuildFile( + "syntax: 'proto3'" "name: 'foo.proto' " "enum_type {" " name: 'FooEnum' " |