Commit 49fcd4f7 authored by Jon Skeet's avatar Jon Skeet

Merge extensions correctly

parent 642a8140
......@@ -351,6 +351,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
foreach (FieldDescriptor field in Descriptor.Fields) {
SourceGenerators.CreateFieldGenerator(field).GenerateMergingCode(writer);
}
// if message type has extensions
if (Descriptor.Proto.ExtensionRangeCount > 0) {
writer.WriteLine(" this.MergeExtensionFields(other);");
}
writer.WriteLine("this.MergeUnknownFields(other.UnknownFields);");
writer.WriteLine("return this;");
writer.Outdent();
......
......@@ -313,7 +313,6 @@ namespace Google.ProtocolBuffers {
.GetExtensionCount(UnitTestProtoFile.RepeatedInt32Extension));
}
/* Reinstate this test in the commit where it's fixed...
[Test]
public void ExtensionMergeFrom() {
TestAllExtensions original = TestAllExtensions.CreateBuilder()
......@@ -323,7 +322,6 @@ namespace Google.ProtocolBuffers {
Assert.IsTrue((merged.HasExtension(UnitTestProtoFile.OptionalInt32Extension)));
Assert.AreEqual(1, (int)merged.GetExtension(UnitTestProtoFile.OptionalInt32Extension));
}
*/
/* Removed multiple files option for the moment
[Test]
......
......@@ -194,6 +194,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(TestMessageSet other) {
if (other == TestMessageSet.DefaultInstance) return this;
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......
......@@ -4884,6 +4884,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(TestAllExtensions other) {
if (other == TestAllExtensions.DefaultInstance) return this;
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -7597,6 +7598,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override Builder MergeFrom(TestEmptyMessageWithExtensions other) {
if (other == TestEmptyMessageWithExtensions.DefaultInstance) return this;
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -10714,6 +10716,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (other.HasMyFloat) {
MyFloat = other.MyFloat;
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......
......@@ -3936,6 +3936,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.uninterpretedOption_.Count != 0) {
base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_);
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -4273,6 +4274,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.uninterpretedOption_.Count != 0) {
base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_);
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -4565,6 +4567,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.uninterpretedOption_.Count != 0) {
base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_);
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -4839,6 +4842,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.uninterpretedOption_.Count != 0) {
base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_);
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -5063,6 +5067,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.uninterpretedOption_.Count != 0) {
base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_);
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -5287,6 +5292,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.uninterpretedOption_.Count != 0) {
base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_);
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......@@ -5511,6 +5517,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.uninterpretedOption_.Count != 0) {
base.AddRange(other.uninterpretedOption_, result.uninterpretedOption_);
}
this.MergeExtensionFields(other);
this.MergeUnknownFields(other.UnknownFields);
return this;
}
......
......@@ -284,15 +284,12 @@ namespace Google.ProtocolBuffers {
throw new ArgumentException("MergeFrom(IMessage) can only merge messages of the same type.");
}
fields.MergeFrom(other);
MergeUnknownFields(other.UnknownFields);
return this;
}
public override Builder MergeFrom(DynamicMessage other) {
if (other.DescriptorForType != type) {
throw new ArgumentException("MergeFrom(IMessage) can only merge messages of the same type.");
}
fields.MergeFrom(other);
return this;
return MergeFrom((IMessage)other);
}
public override DynamicMessage Build() {
......
......@@ -166,5 +166,9 @@ namespace Google.ProtocolBuffers {
return base.AddRepeatedField(field, value);
}
}
protected void MergeExtensionFields(ExtendableMessage<TMessage, TBuilder> other) {
MessageBeingBuilt.Extensions.MergeFrom(other.Extensions);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment