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

Issue 2891 - Ambiguous Vector instances #3100

Merged
merged 2 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions kernel/src/main/scala/cats/kernel/instances/ListInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
10 changes: 6 additions & 4 deletions kernel/src/main/scala/cats/kernel/instances/QueueInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
11 changes: 11 additions & 0 deletions tests/src/test/scala/cats/tests/ListSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]
}
}
11 changes: 11 additions & 0 deletions tests/src/test/scala/cats/tests/QueueSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]
}
}
11 changes: 11 additions & 0 deletions tests/src/test/scala/cats/tests/VectorSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]
}
}