From 3623c9e2dab53b4160e2044f47d59f384dc8f2f8 Mon Sep 17 00:00:00 2001 From: Filippo Mariotti Date: Sat, 5 Oct 2019 02:26:15 +0100 Subject: [PATCH 1/2] Changed precedence of kernel instances for Vector --- .../scala/cats/kernel/instances/VectorInstances.scala | 11 +++++++---- .../scala-2.13+/cats/tests/ScalaVersionSpecific.scala | 6 ++---- tests/src/test/scala/cats/tests/VectorSuite.scala | 11 +++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/kernel/src/main/scala/cats/kernel/instances/VectorInstances.scala b/kernel/src/main/scala/cats/kernel/instances/VectorInstances.scala index 75193a7e64..5acc4a3488 100644 --- a/kernel/src/main/scala/cats/kernel/instances/VectorInstances.scala +++ b/kernel/src/main/scala/cats/kernel/instances/VectorInstances.scala @@ -6,19 +6,22 @@ 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 catsKernelStdPartialOrderForVector[A: PartialOrder]: PartialOrder[Vector[A]] = - new VectorPartialOrder[A] - implicit def catsKernelStdHashForVector[A: Hash]: Hash[Vector[A]] = new VectorHash[A] } -private[instances] trait VectorInstances2 { +private[instances] trait VectorInstances2 extends VectorInstances3 { + implicit def catsKernelStdPartialOrderForVector[A: PartialOrder]: PartialOrder[Vector[A]] = + new VectorPartialOrder[A] +} + +private[instances] trait VectorInstances3 { implicit def catsKernelStdEqForVector[A: Eq]: Eq[Vector[A]] = new VectorEq[A] } diff --git a/tests/src/test/scala-2.13+/cats/tests/ScalaVersionSpecific.scala b/tests/src/test/scala-2.13+/cats/tests/ScalaVersionSpecific.scala index 43c3230dd9..76af75af33 100644 --- a/tests/src/test/scala-2.13+/cats/tests/ScalaVersionSpecific.scala +++ b/tests/src/test/scala-2.13+/cats/tests/ScalaVersionSpecific.scala @@ -123,11 +123,9 @@ trait ScalaVersionSpecificParallelSuite { self: ParallelSuite => } // Can't test Parallel here, as Applicative[ZipLazyList].pure doesn't terminate - checkAll("Parallel[LazyList]", - NonEmptyParallelTests[LazyList].nonEmptyParallel[Int, String]) + checkAll("Parallel[LazyList]", NonEmptyParallelTests[LazyList].nonEmptyParallel[Int, String]) - checkAll("Parallel[NonEmptyLazyList]", - ParallelTests[NonEmptyLazyList].parallel[Int, String]) + checkAll("Parallel[NonEmptyLazyList]", ParallelTests[NonEmptyLazyList].parallel[Int, String]) } trait ScalaVersionSpecificRegressionSuite { self: RegressionSuite => diff --git a/tests/src/test/scala/cats/tests/VectorSuite.scala b/tests/src/test/scala/cats/tests/VectorSuite.scala index 0f89646539..abf195dae4 100644 --- a/tests/src/test/scala/cats/tests/VectorSuite.scala +++ b/tests/src/test/scala/cats/tests/VectorSuite.scala @@ -54,4 +54,15 @@ 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]]] + } } From 4afb3a3b494359359152ebd492b1471c0896bcce Mon Sep 17 00:00:00 2001 From: Filippo Mariotti Date: Sat, 5 Oct 2019 03:09:21 +0100 Subject: [PATCH 2/2] Fixed also List and Queue --- .../scala/cats/kernel/instances/ListInstances.scala | 10 ++++++---- .../scala/cats/kernel/instances/QueueInstances.scala | 10 ++++++---- tests/src/test/scala/cats/tests/ListSuite.scala | 11 +++++++++++ tests/src/test/scala/cats/tests/QueueSuite.scala | 11 +++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/kernel/src/main/scala/cats/kernel/instances/ListInstances.scala b/kernel/src/main/scala/cats/kernel/instances/ListInstances.scala index 0e1cf882ce..40b705ef70 100644 --- a/kernel/src/main/scala/cats/kernel/instances/ListInstances.scala +++ b/kernel/src/main/scala/cats/kernel/instances/ListInstances.scala @@ -13,14 +13,16 @@ trait ListInstances extends ListInstances1 { } private[instances] trait ListInstances1 extends ListInstances2 { - 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 ListInstances2 { +private[instances] trait ListInstances2 extends ListInstances3 { + implicit def catsKernelStdPartialOrderForList[A: PartialOrder]: PartialOrder[List[A]] = + new ListPartialOrder[A] +} + +private[instances] trait ListInstances3 { implicit def catsKernelStdEqForList[A: Eq]: Eq[List[A]] = new ListEq[A] } diff --git a/kernel/src/main/scala/cats/kernel/instances/QueueInstances.scala b/kernel/src/main/scala/cats/kernel/instances/QueueInstances.scala index 76a8ec7e18..913fb8cf60 100644 --- a/kernel/src/main/scala/cats/kernel/instances/QueueInstances.scala +++ b/kernel/src/main/scala/cats/kernel/instances/QueueInstances.scala @@ -13,14 +13,16 @@ trait QueueInstances extends QueueInstances1 { } private[instances] trait QueueInstances1 extends QueueInstances2 { - 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 QueueInstances2 { +private[instances] trait QueueInstances2 extends QueueInstances3 { + implicit def catsKernelStdPartialOrderForQueue[A: PartialOrder]: PartialOrder[Queue[A]] = + new QueuePartialOrder[A] +} + +private[instances] trait QueueInstances3 { implicit def catsKernelStdEqForQueue[A: Eq]: Eq[Queue[A]] = new QueueEq[A] } diff --git a/tests/src/test/scala/cats/tests/ListSuite.scala b/tests/src/test/scala/cats/tests/ListSuite.scala index c5301365f1..7b3f0d7eb0 100644 --- a/tests/src/test/scala/cats/tests/ListSuite.scala +++ b/tests/src/test/scala/cats/tests/ListSuite.scala @@ -59,4 +59,15 @@ 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]]] + } } diff --git a/tests/src/test/scala/cats/tests/QueueSuite.scala b/tests/src/test/scala/cats/tests/QueueSuite.scala index a632022465..f428dedde5 100644 --- a/tests/src/test/scala/cats/tests/QueueSuite.scala +++ b/tests/src/test/scala/cats/tests/QueueSuite.scala @@ -32,4 +32,15 @@ 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]]] + } }