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

Fixed a bug in the Order and PartialOrder instances for Tuple2+ where only the first element was used in comparisons #1062

Merged
merged 1 commit into from
May 25, 2016

Conversation

mpilquist
Copy link
Member

Before this fix:

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

scala> (1 -> 2) === (1 -> 3)
res0: Boolean = true

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> showCode(reify { (1 -> 2) === (1 -> 3) }.tree)
res1: String = implicits.eqSyntax(Predef.ArrowAssoc(1).->(2))(implicits.tuple2Order(implicits.intOrder, implicits.intOrder)).===(Predef.ArrowAssoc(1).->(3))

This is because we pick up the Order[Tuple2[..]] instance, which is erroneously defined like this:

  implicit def tuple2Order[A0, A1](implicit A0: Order[A0], A1: Order[A1]): Order[(A0, A1)] =
    new Order[(A0, A1)] {
      def compare(x: (A0, A1), y: (A0, A1)): Int =
        A0.compare(x._1, y._1)
    }

I think we should probably publish a 0.6.1 with this fix too as it is really nasty -- code compiles but values end up being report equal which aren't.

/cc @non

… only the first element was used in comparisons
@non
Copy link
Contributor

non commented May 25, 2016

👍 ugh thanks for the catch!

@non
Copy link
Contributor

non commented May 25, 2016

(we need more tests for the generated code!)

@ceedubs
Copy link
Contributor

ceedubs commented May 25, 2016

Yikes :(. Thanks!

@ceedubs ceedubs merged commit 011fc52 into typelevel:master May 25, 2016
@ceedubs
Copy link
Contributor

ceedubs commented May 25, 2016

It'd probably be nice to put this into a patch release. I won't have much availability to help with that for the next few days though :(

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.

3 participants