SimpleDiagnostic GetHashCode is inconsistent #57
Labels
2 - Ready
Area-Analyzers
Area-Compilers
Bug
Concept-API
This issue involves adding, removing, clarification, or modification of an API.
Verified
Milestone
To make Microsoft.CodeAnalysis.Diagnostic work with Sets and other data structures that requires GetHashCode to be implemented correctly you have to have a GetHashCode method with this property:
x.Equals(y) \implies x.GetHashCode() == y.GetHashCode() \forall x,y
Currently SimpleDiagnostic's GetHashCode combines the hash codes of its properties including a GetHashCode on the object[] messageArgs which is using the reference to that array, not its contents to generate the hash code. Equals however is comparing the objects in the array (using Enumerable.SequenceEqual) . So currently you can have two diagnostics that are Equal in terms of IEquatable.Equals but with GetHashCode returning different values.
http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis/Diagnostic/Diagnostic_SimpleDiagnostic.cs,134
http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis/Diagnostic/Diagnostic_SimpleDiagnostic.cs,120
The text was updated successfully, but these errors were encountered: