Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleDiagnostic GetHashCode is inconsistent #57

Closed
pdelvo opened this issue Jan 22, 2015 · 1 comment · Fixed by #209
Closed

SimpleDiagnostic GetHashCode is inconsistent #57

pdelvo opened this issue Jan 22, 2015 · 1 comment · Fixed by #209
Assignees
Labels
2 - Ready Area-Analyzers Area-Compilers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. Verified
Milestone

Comments

@pdelvo
Copy link
Contributor

pdelvo commented Jan 22, 2015

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

@VSadov
Copy link
Member

VSadov commented Jan 22, 2015

Looks like a bug. GetHashCode should not be more specific than Equals by requiring actual reference equality of message array.

@VSadov VSadov added Bug Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. labels Jan 22, 2015
@srivatsn srivatsn added this to the 1.0 milestone Jan 24, 2015
@srivatsn srivatsn modified the milestones: 1.0 (stable), 1.0-rc2 Jan 29, 2015
dibarbet added a commit to dibarbet/roslyn that referenced this issue Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 - Ready Area-Analyzers Area-Compilers Bug Concept-API This issue involves adding, removing, clarification, or modification of an API. Verified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants