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 Quantity hashcode method. #307

Merged
merged 2 commits into from
Jun 4, 2018

Conversation

Passarinho4
Copy link
Contributor

Hi,
I've fixed hashcode method in Quantity class. The previous one was breaking the equals/hashcode conduct. It is a very serious bug, so please review it and merge if only possible.

@cquiroz
Copy link
Collaborator

cquiroz commented May 25, 2018

Would you mind adding tests. This is serious enough to warrant some automated test

@Passarinho4
Copy link
Contributor Author

Passarinho4 commented May 28, 2018

I've added simple hashcode test. Is this enough? :) @cquiroz

@Passarinho4
Copy link
Contributor Author

Anyone? @garyKeorkunian @cquiroz @nornagon
I believe that this is very crucial fix and should be merged and released asap. Is this project alive?

@cquiroz
Copy link
Collaborator

cquiroz commented Jun 4, 2018

That looks good for me

@Passarinho4
Copy link
Contributor Author

Ok, so could you ack the review, because I cannot merge it without your permission? And what about releasing the new version?

Copy link
Collaborator

@derekmorr derekmorr left a comment

Choose a reason for hiding this comment

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

I'm not sure about the first test, it just looks like an identity test, but I don't object.

@derekmorr derekmorr merged commit ed961e4 into typelevel:master Jun 4, 2018
@derekmorr
Copy link
Collaborator

Thanks for the PR. Sorry for the delay.

@Passarinho4
Copy link
Contributor Author

Whenever hashcode is invoked on the same object it should return the same value. This is the reason for this test. Thanks! :)

@@ -176,7 +178,9 @@ abstract class Quantity[A <: Quantity[A]] extends Serializable with Ordered[A] {
*
* @return
*/
override def hashCode() = toString.hashCode()
override def hashCode() = {
Objects.hash(dimension, Double.box(to(dimension.primaryUnit)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, the resulting hashCode is not stable across JVM runs because the dimension itself may not have a stable hashCode.

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.

4 participants