Skip to content

Commit

Permalink
Fix broken binary compatibility (#3163)
Browse files Browse the repository at this point in the history
* Revert "Issue 2891 - Ambiguous Vector instances (#3100)"

This reverts commit e766998.

* Revert "Changed precedence of tupled instances for Hash and PartialOrder (#3105)"

This reverts commit 6e7ff8f.

* Move method back to avoid bincompat breakage

* Reinstate doc fix from #3105
  • Loading branch information
travisbrown authored and rossabaker committed Nov 26, 2019
1 parent f810dff commit 6697edc
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 83 deletions.
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Thank you for contributing to Cats!

This is a kind reminder to run `sbt +prePR` and commit the changed files, if any, before submitting.
This is a kind reminder to run `sbt +prePR` and commit the changed files, if any, before submitting.


10 changes: 4 additions & 6 deletions kernel/src/main/scala/cats/kernel/instances/ListInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ trait ListInstances extends ListInstances1 {
}

private[instances] trait ListInstances1 extends ListInstances2 {
implicit def catsKernelStdHashForList[A: Hash]: Hash[List[A]] =
new ListHash[A]
}

private[instances] trait ListInstances2 extends ListInstances3 {
implicit def catsKernelStdPartialOrderForList[A: PartialOrder]: PartialOrder[List[A]] =
new ListPartialOrder[A]

implicit def catsKernelStdHashForList[A: Hash]: Hash[List[A]] =
new ListHash[A]
}

private[instances] trait ListInstances3 {
private[instances] trait ListInstances2 {
implicit def catsKernelStdEqForList[A: Eq]: Eq[List[A]] =
new ListEq[A]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ trait OptionInstances extends OptionInstances0 {
new OptionOrder[A]
implicit def catsKernelStdCommutativeMonoidForOption[A: CommutativeSemigroup]: CommutativeMonoid[Option[A]] =
new OptionCommutativeMonoid[A]
implicit def catsKernelStdMonoidForOption[A: Semigroup]: Monoid[Option[A]] =
new OptionMonoid[A]
}

private[instances] trait OptionInstances0 extends OptionInstances1 {
implicit def catsKernelStdPartialOrderForOption[A: PartialOrder]: PartialOrder[Option[A]] =
new OptionPartialOrder[A]
implicit def catsKernelStdMonoidForOption[A: Semigroup]: Monoid[Option[A]] =
new OptionMonoid[A]
}

private[instances] trait OptionInstances1 extends OptionInstances2 {
Expand Down
10 changes: 4 additions & 6 deletions kernel/src/main/scala/cats/kernel/instances/QueueInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ trait QueueInstances extends QueueInstances1 {
}

private[instances] trait QueueInstances1 extends QueueInstances2 {
implicit def catsKernelStdHashForQueue[A: Hash]: Hash[Queue[A]] =
new QueueHash[A]
}

private[instances] trait QueueInstances2 extends QueueInstances3 {
implicit def catsKernelStdPartialOrderForQueue[A: PartialOrder]: PartialOrder[Queue[A]] =
new QueuePartialOrder[A]

implicit def catsKernelStdHashForQueue[A: Hash]: Hash[Queue[A]] =
new QueueHash[A]
}

private[instances] trait QueueInstances3 {
private[instances] trait QueueInstances2 {
implicit def catsKernelStdEqForQueue[A: Eq]: Eq[Queue[A]] =
new QueueEq[A]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import compat.scalaVersionSpecific._
trait VectorInstances extends VectorInstances1 {
implicit def catsKernelStdOrderForVector[A: Order]: Order[Vector[A]] =
new VectorOrder[A]

implicit def catsKernelStdMonoidForVector[A]: Monoid[Vector[A]] =
new VectorMonoid[A]
}

private[instances] trait VectorInstances1 extends VectorInstances2 {
implicit def catsKernelStdHashForVector[A: Hash]: Hash[Vector[A]] =
new VectorHash[A]
}

private[instances] trait VectorInstances2 extends VectorInstances3 {
implicit def catsKernelStdPartialOrderForVector[A: PartialOrder]: PartialOrder[Vector[A]] =
new VectorPartialOrder[A]

implicit def catsKernelStdHashForVector[A: Hash]: Hash[Vector[A]] =
new VectorHash[A]
}

private[instances] trait VectorInstances3 {
private[instances] trait VectorInstances2 {
implicit def catsKernelStdEqForVector[A: Eq]: Eq[Vector[A]] =
new VectorEq[A]
}
Expand Down
12 changes: 6 additions & 6 deletions project/KernelBoiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ object KernelBoiler {
.mkString(s"$tupleNHeader(", ", ", ")")}.hashCode()
def eqv(x: ${`(A..N)`}, y: ${`(A..N)`}): Boolean = ${binMethod("eqv").mkString(" && ")}
}

implicit def catsKernelStdPartialOrderForTuple${arity}[${`A..N`}](implicit ${constraints("PartialOrder")}): PartialOrder[${`(A..N)`}] =
new PartialOrder[${`(A..N)`}] {
def partialCompare(x: ${`(A..N)`}, y: ${`(A..N)`}): Double =
${binMethod("partialCompare").mkString("Array(", ", ", ")")}.find(_ != 0.0).getOrElse(0.0)
}
"""
}
),
Expand All @@ -211,12 +217,6 @@ object KernelBoiler {
import tv._
def content =
block"""
implicit def catsKernelStdPartialOrderForTuple${arity}[${`A..N`}](implicit ${constraints("PartialOrder")}): PartialOrder[${`(A..N)`}] =
new PartialOrder[${`(A..N)`}] {
def partialCompare(x: ${`(A..N)`}, y: ${`(A..N)`}): Double =
${binMethod("partialCompare").mkString("Array(", ", ", ")")}.find(_ != 0.0).getOrElse(0.0)
}

implicit def catsKernelStdBandForTuple${arity}[${`A..N`}](implicit ${constraints("Band")}): Band[${`(A..N)`}] =
new Band[${`(A..N)`}] {
def combine(x: ${`(A..N)`}, y: ${`(A..N)`}): ${`(A..N)`} = ${binTuple("combine")}
Expand Down
22 changes: 0 additions & 22 deletions tests/src/test/scala/cats/tests/EqSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import cats.laws.discipline.{ContravariantMonoidalTests, MiniInt}
import cats.laws.discipline.arbitrary._
import cats.laws.discipline.eq._

import scala.collection.immutable.Queue

class EqSuite extends CatsSuite {
Invariant[Eq]
Contravariant[Eq]
Expand All @@ -17,24 +15,4 @@ class EqSuite extends CatsSuite {
checkAll("Eq", ContravariantMonoidalTests[Eq].contravariantMonoidal[MiniInt, Boolean, Boolean])
checkAll("ContravariantMonoidal[Eq]", SerializableTests.serializable(ContravariantMonoidal[Eq]))

test("The Eq instance for tuples of A is not ambiguous when A has a Hash and a PartialOrder") {

import cats.kernel.{Hash, PartialOrder}

trait A
implicit def po: PartialOrder[A] = ???
implicit def ho: Hash[A] = ???

lazy val a2 = implicitly[Eq[(A, A)]]
lazy val b2 = implicitly[Eq[(List[A], List[A])]]
lazy val c2 = implicitly[Eq[(Set[A], Set[A])]]
lazy val d2 = implicitly[Eq[(Vector[A], Vector[A])]]
lazy val e2 = implicitly[Eq[(Queue[A], Queue[A])]]

lazy val a3 = implicitly[Eq[(A, A, A)]]
lazy val b3 = implicitly[Eq[(List[A], List[A], List[A])]]
lazy val c3 = implicitly[Eq[(Set[A], Set[A], Set[A])]]
lazy val d3 = implicitly[Eq[(Vector[A], Vector[A], Vector[A])]]
lazy val e3 = implicitly[Eq[(Queue[A], Queue[A], Queue[A])]]
}
}
11 changes: 0 additions & 11 deletions tests/src/test/scala/cats/tests/ListSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ class ListSuite extends CatsSuite {
l.show should ===(l.toString)
}
}

test("the instance for `Eq[List[A]]` is not ambiguous when A has a Hash and a PartialOrder") {

import cats.kernel.{Hash, PartialOrder}

trait A
implicit def po: PartialOrder[A] = ???
implicit def ho: Hash[A] = ???

lazy val _ = implicitly[Eq[List[A]]]
}
}

final class ListInstancesSuite extends AnyFunSuiteLike {
Expand Down
11 changes: 0 additions & 11 deletions tests/src/test/scala/cats/tests/QueueSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,4 @@ class QueueSuite extends CatsSuite {
Queue(1, 2, 3).show should ===("Queue(1, 2, 3)")
Queue.empty[Int].show should ===("Queue()")
}

test("the instance for `Eq[Queue[A]]` is not ambiguous when A has a Hash and a PartialOrder") {

import cats.kernel.{Hash, PartialOrder}

trait A
implicit def po: PartialOrder[A] = ???
implicit def ho: Hash[A] = ???

lazy val _ = implicitly[Eq[Queue[A]]]
}
}
11 changes: 0 additions & 11 deletions tests/src/test/scala/cats/tests/VectorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ class VectorSuite extends CatsSuite {
test("toNev on empty vector returns None") {
assert(Vector.empty[Int].toNev == None)
}

test("the instance for `Eq[Vector[A]]` is not ambiguous when A has a Hash and a PartialOrder") {

import cats.kernel.{Hash, PartialOrder}

trait A
implicit def po: PartialOrder[A] = ???
implicit def ho: Hash[A] = ???

lazy val _ = implicitly[Eq[Vector[A]]]
}
}

final class VectorInstancesSuite extends AnyFunSuiteLike {
Expand Down

0 comments on commit 6697edc

Please sign in to comment.