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

Fix equality check bug in ExpressionKey #363

Merged
merged 3 commits into from
Jun 11, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Jun 5, 2017

This PR is a cleaned-up version of #134. It fixes the buggy Equals and GetHashCode implementations in Interceptor.ExpressionKey.

This closes #135, and closes #328, and closes #374.

{
if (value != null)
{
hash = unchecked((hash * 397) ^ value.GetHashCode());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't care whether the hash value overflows or not, but we do not want overflows to trigger an exception. That is why unchecked is necessary here.

kostadinmarinov and others added 3 commits June 11, 2017 19:09
The equality check in ExpressionKey is wrong. The check must be
conjunction (&), but not disjunction(|), because then the values don't
matter in that check and they are just skipped. So, invocations:

 aMock.Setup(m => m.Foo(i1, i2));
 aMock.Setup(m => m.Foo(i2, i1));

have the same expression key, but this is not correct.
 1. Fix `ExpressionKey.Equals` so that it works correctly for boxed
    value types (by using object.Equals instead of ==).

 2. Update the test code (xUnit no longer has `Assert.DoesNotThrow`).
Issue 328 revealed that ExpressionKey did not perform equality check-
ing correctly for objects with the same hash code. This commit adds
tests for that specific scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants