internal/impl: treat a nil oneof wrapper as if it were unset
The old implementation had the behavior where a nil wrapper value:
m := new(foopb.Message)
m.OneofField = (*foopb.Message_OneofUint32)(nil)
was functionally equivalent to it being directly set to nil:
m := new(foopb.Message)
m.OneofField = nil
preserve this semantic in both the table-drive implementation
and the reflection implementation.
Change-Id: Ie44d51e044d4822e61d0e646fbc44aa8d9b90c1f
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/189559
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/proto/decode_test.go b/proto/decode_test.go
index 9819838..3d7d6b6 100644
--- a/proto/decode_test.go
+++ b/proto/decode_test.go
@@ -122,6 +122,19 @@
}
}
+func TestDecodeOneofNilWrapper(t *testing.T) {
+ wire := pack.Message{
+ pack.Tag{111, pack.VarintType}, pack.Varint(1111),
+ }.Marshal()
+ m := &testpb.TestAllTypes{OneofField: (*testpb.TestAllTypes_OneofUint32)(nil)}
+ if err := proto.Unmarshal(wire, m); err != nil {
+ t.Fatal(err)
+ }
+ if got := m.GetOneofUint32(); got != 1111 {
+ t.Errorf("GetOneofUint32() = %v, want %v", got, 1111)
+ }
+}
+
var testProtos = []testProto{
{
desc: "basic scalar types",