mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-04-07 13:22:52 +00:00
proto: allow nil with Clone
The v1 behavior of Clone returned nil as is. Replicate this behavior in v2 for easier migration. Change-Id: I79d93f15dd9913604027e31e5d9ff309e0c2da61 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/220437 Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
ec552f691d
commit
49f8611134
@ -39,6 +39,9 @@ func Clone(m Message) Message {
|
|||||||
// Embedding protobuf messages breaks this since the parent type will have
|
// Embedding protobuf messages breaks this since the parent type will have
|
||||||
// a forwarded ProtoReflect method, but the Interface method will return
|
// a forwarded ProtoReflect method, but the Interface method will return
|
||||||
// the underlying embedded message type.
|
// the underlying embedded message type.
|
||||||
|
if m == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
src := m.ProtoReflect()
|
src := m.ProtoReflect()
|
||||||
if !src.IsValid() {
|
if !src.IsValid() {
|
||||||
return src.Type().Zero().Interface()
|
return src.Type().Zero().Interface()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user