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

Unlawful Hash instances for Function0 #2952

Closed
travisbrown opened this issue Jul 19, 2019 · 3 comments
Closed

Unlawful Hash instances for Function0 #2952

travisbrown opened this issue Jul 19, 2019 · 3 comments

Comments

@travisbrown
Copy link
Contributor

I just noticed that Hash[() => A] doesn't match hashCode, and (possibly worse) it evaluates the function:

scala> val thunk = () => "abcd"
thunk: () => String = $$Lambda$4719/1999191506@1ef9f59

scala> thunk.hashCode
res0: Int = 32481113

scala> import cats.implicits._
import cats.implicits._

scala> thunk.hash
res1: Int = 2987074

scala> "abcd".hashCode
res2: Int = 2987074

We should decide whether / how to handle this and add something like this to LawTests in the kernel-laws tests:

checkAll("Hash[() => Int]", HashTests[() => Int].hash)

(I confirmed that it fails now.)

@kailuowang
Copy link
Contributor

Any reason why this is closed?

@travisbrown
Copy link
Contributor Author

@kailuowang I'm not sure it's unintended / not the right behavior. Will take a closer look tomorrow.

@kailuowang
Copy link
Contributor

thanks! FWIW, this is the PR that added the code. #1712

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

No branches or pull requests

2 participants