diff --git a/csharp/protos/unittest_issues.proto b/csharp/protos/unittest_issues.proto index 388998f0a0..f46c20e4da 100644 --- a/csharp/protos/unittest_issues.proto +++ b/csharp/protos/unittest_issues.proto @@ -156,3 +156,17 @@ message MixedRegularAndOptional { string regular_field = 1; optional string optional_field = 2; } + +message OneofWithNoneField { + oneof test { + string x = 1; + string none = 2; + } +} + +message OneofWithNoneName { + oneof none { + string x = 1; + string y = 2; + } +} \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/IssuesTest.cs b/csharp/src/Google.Protobuf.Test/IssuesTest.cs index a46467ca07..695398918b 100644 --- a/csharp/src/Google.Protobuf.Test/IssuesTest.cs +++ b/csharp/src/Google.Protobuf.Test/IssuesTest.cs @@ -112,5 +112,21 @@ namespace Google.Protobuf // See https://github.com/protocolbuffers/protobuf/pull/7289 cis.AssertNextTag(WireFormat.MakeTag(11, WireFormat.WireType.Varint)); } + + [Test] + public void NoneFieldInOneof() + { + var message = new OneofWithNoneField(); + var emptyHashCode = message.GetHashCode(); + Assert.AreEqual(OneofWithNoneField.TestOneofCase.None, message.TestCase); + message.None = "test"; + Assert.AreEqual(OneofWithNoneField.TestOneofCase.None_, message.TestCase); + Assert.AreNotEqual(emptyHashCode, message.GetHashCode()); + + var bytes = message.ToByteArray(); + var parsed = OneofWithNoneField.Parser.ParseFrom(bytes); + Assert.AreEqual(message, parsed); + Assert.AreEqual("test", parsed.None); + } } }