From e831c33179b55b753630e0555cdc32b83b81e954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20H=C3=B6ppner?= Date: Tue, 31 Jan 2023 10:54:20 +0100 Subject: [PATCH] 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 Reviewed-by: Chressie Himpel --- proto/equal.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/proto/equal.go b/proto/equal.go index baa1bc196..1a0be1b03 100644 --- a/proto/equal.go +++ b/proto/equal.go @@ -31,8 +31,13 @@ import ( // - Maps are equal if they have the same set of keys and // the corresponding value for each key is equal. // -// If two messages marshal to the same bytes under deterministic serialization, -// then Equal is guaranteed to report true. +// An invalid message is not equal to a valid message. +// An invalid message is only equal to another invalid message of the +// same type. An invalid message often corresponds to a nil pointer +// of the concrete message type. For example, (*pb.M)(nil) is not equal +// to &pb.M{}. +// If two valid messages marshal to the same bytes under deterministic +// serialization, then Equal is guaranteed to report true. func Equal(x, y Message) bool { if x == nil || y == nil { return x == nil && y == nil