proto/equal: equate nil
Modify Equal to treat nil messages as equal iff both are nil.
Of special note, a typed nil pointer to T is equal to a new(T)
since they are indistinguishable from a protobuf reflection.
Change-Id: Ibf90b43a982e7376e07b4159be198f06230ec194
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/196618
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/proto/equal.go b/proto/equal.go
index 44f840a..7b513bd 100644
--- a/proto/equal.go
+++ b/proto/equal.go
@@ -29,6 +29,9 @@
// Maps are equal if they have the same set of keys, where the pair of values
// for each key is also equal.
func Equal(x, y Message) bool {
+ if x == nil || y == nil {
+ return x == nil && y == nil
+ }
return equalMessage(x.ProtoReflect(), y.ProtoReflect())
}