Skip to content

Commit e831c33

Browse files
committed
proto: document Equal behavior of invalid messages
The doc comment of proto.Equal now explicitly describes the behavior in the case when one message is valid and other is invalid. Change-Id: Ifeba40277c7da25193d46ad496e910f9b63eb795 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/464275 Reviewed-by: Joseph Tsai <[email protected]> Reviewed-by: Chressie Himpel <[email protected]>
1 parent 358fe40 commit e831c33

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

proto/equal.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ import (
3131
// - Maps are equal if they have the same set of keys and
3232
// the corresponding value for each key is equal.
3333
//
34-
// If two messages marshal to the same bytes under deterministic serialization,
35-
// then Equal is guaranteed to report true.
34+
// An invalid message is not equal to a valid message.
35+
// An invalid message is only equal to another invalid message of the
36+
// same type. An invalid message often corresponds to a nil pointer
37+
// of the concrete message type. For example, (*pb.M)(nil) is not equal
38+
// to &pb.M{}.
39+
// If two valid messages marshal to the same bytes under deterministic
40+
// serialization, then Equal is guaranteed to report true.
3641
func Equal(x, y Message) bool {
3742
if x == nil || y == nil {
3843
return x == nil && y == nil

0 commit comments

Comments
 (0)