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/internal/testprotos/test/test.proto b/internal/testprotos/test/test.proto
index f78de65..e501b7a 100644
--- a/internal/testprotos/test/test.proto
+++ b/internal/testprotos/test/test.proto
@@ -124,6 +124,11 @@
double oneof_double = 118;
NestedEnum oneof_enum = 119;
}
+
+ // A oneof with exactly one field.
+ oneof oneof_optional {
+ uint32 oneof_optional_uint32 = 120;
+ }
}
message TestDeprecatedMessage {