From 9bbd7078a0c78ff7126c37c2b9a160c365e69c95 Mon Sep 17 00:00:00 2001 From: Solaris-star <820622658@qq.com> Date: Wed, 22 Jul 2026 05:02:35 +0800 Subject: [PATCH] docs: clarify Equal method is skipped when either value is nil The package docs claimed x.Equal(y) runs "even if x or y is nil", but pointers/interfaces short-circuit on nil before tryMethod, so a nil receiver is never used. Document the actual behavior. Fixes #363 --- cmp/compare.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmp/compare.go b/cmp/compare.go index 119af26..b98a256 100644 --- a/cmp/compare.go +++ b/cmp/compare.go @@ -58,8 +58,10 @@ import ( // // - If the values have an Equal method of the form "(T) Equal(T) bool" or // "(T) Equal(I) bool" where T is assignable to I, then use the result of -// x.Equal(y) even if x or y is nil. Otherwise, no such method exists and -// evaluation proceeds to the next rule. +// x.Equal(y) when both values are non-nil. If either value is nil, Equal +// reports whether both are nil without calling the method (so a nil +// receiver never panics). Otherwise, no such method exists and evaluation +// proceeds to the next rule. // // - Lastly, try to compare x and y based on their basic kinds. // Simple kinds like booleans, integers, floats, complex numbers, strings,