mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-30 03:32:49 +00:00
proto: fix equality on nil values of different types
Equal((*M1)(nil), (*M2)(nil)) should be false. Change-Id: I7def8016fcf1e78d9e69f79c23ab44fc3d211bb0 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/213479 Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
parent
2244bc5833
commit
2ad3f248e2
@ -35,8 +35,8 @@ func Equal(x, y Message) bool {
|
||||
}
|
||||
mx := x.ProtoReflect()
|
||||
my := y.ProtoReflect()
|
||||
if !mx.IsValid() || !my.IsValid() {
|
||||
return !mx.IsValid() && !my.IsValid()
|
||||
if mx.IsValid() != my.IsValid() {
|
||||
return false
|
||||
}
|
||||
return equalMessage(mx, my)
|
||||
}
|
||||
|
@ -41,6 +41,21 @@ func TestEqual(t *testing.T) {
|
||||
y: new(testpb.TestAllTypes),
|
||||
eq: true,
|
||||
},
|
||||
{
|
||||
x: (*testpb.TestAllTypes)(nil),
|
||||
y: (*testpb.TestAllExtensions)(nil),
|
||||
eq: false,
|
||||
},
|
||||
{
|
||||
x: (*testpb.TestAllTypes)(nil),
|
||||
y: new(testpb.TestAllExtensions),
|
||||
eq: false,
|
||||
},
|
||||
{
|
||||
x: new(testpb.TestAllTypes),
|
||||
y: new(testpb.TestAllExtensions),
|
||||
eq: false,
|
||||
},
|
||||
|
||||
// Proto2 scalars.
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user