fix(code): replace GetHashCode comparison in ChatCode.Equals with field equality

Equals(object?) was delegating to GetHashCode() comparison, which is
the textbook hash-collision anti-pattern: two distinct ChatCode values
could in principle share a hash and be wrongly reported as equal. The
current GetHashCode implementation packs Type/Source/Target into 24
bits and happens to be collision-free, but the contract is fragile —
any future change to GetHashCode silently breaks Equals.

Replaced with direct field-by-field comparison of Type, Source, Target.
GetHashCode is left unchanged so dictionary/HashSet behavior stays
identical.

Pre-existing upstream issue (CodeRabbit critical finding); fixed in
v1.0.0 standalone cut where we own the codebase.
This commit is contained in:
2026-05-03 21:57:17 +02:00
parent fea4965889
commit 1d557f1b0e
+1 -4
View File
@@ -91,13 +91,10 @@ public class ChatCode
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
if (obj == null)
return false;
if (obj is not ChatCode code) if (obj is not ChatCode code)
return false; return false;
return GetHashCode() == code.GetHashCode(); return Type == code.Type && Source == code.Source && Target == code.Target;
} }
public override int GetHashCode() public override int GetHashCode()