Skip to content

Commit

Permalink
Issue #173: Ambiguity during Arrow instance resolution for ZIO and ZM…
Browse files Browse the repository at this point in the history
…anaged (#174)

* fixed Ambiguity during Arrow instance resolution for ZIO and ZManaged

* fixing 'parameter is never used' compiler error on 2.12

* moving getArrow method and invocations to summoningInstancesTest
  • Loading branch information
Ievgen Garkusha authored Apr 29, 2020
1 parent 8aeebb9 commit f58ade9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
14 changes: 8 additions & 6 deletions interop-cats/shared/src/main/scala/zio/interop/cats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ abstract class CatsInstances extends CatsInstances1 {
implicit final def rioArrowInstance: ArrowChoice[RIO] =
zioArrowInstance0.asInstanceOf[ArrowChoice[RIO]]

implicit final def urioArrowInstance: ArrowChoice[URIO] =
zioArrowInstance0.asInstanceOf[ArrowChoice[URIO]]

implicit final def zioArrowInstance[E]: ArrowChoice[ZIO[*, E, *]] =
zioArrowInstance0.asInstanceOf[ArrowChoice[ZIO[*, E, *]]]

implicit final def contravariantInstance[E, A]: Contravariant[ZIO[*, E, A]] =
contravariantInstance0.asInstanceOf[Contravariant[ZIO[*, E, A]]]

Expand All @@ -131,6 +125,9 @@ abstract class CatsInstances extends CatsInstances1 {

sealed abstract class CatsInstances1 extends CatsInstances2 {

implicit final def urioArrowInstance: ArrowChoice[URIO] =
zioArrowInstance0.asInstanceOf[ArrowChoice[URIO]]

implicit final def parallelInstance[R, E]: Parallel.Aux[ZIO[R, E, *], ParIO[R, E, *]] =
parallelInstance0.asInstanceOf[Parallel.Aux[ZIO[R, E, *], ParIO[R, E, *]]]

Expand All @@ -148,6 +145,11 @@ sealed abstract class CatsInstances1 extends CatsInstances2 {
}

sealed abstract class CatsInstances2 {
protected[this] val zioArrowInstance0: ArrowChoice[ZIO[*, Any, *]] = new CatsArrow

implicit final def zioArrowInstance[E]: ArrowChoice[ZIO[*, E, *]] =
zioArrowInstance0.asInstanceOf[ArrowChoice[ZIO[*, E, *]]]

implicit final def monadErrorInstance[R, E]: MonadError[ZIO[R, E, *], E] =
monadErrorInstance0.asInstanceOf[MonadError[ZIO[R, E, *], E]]

Expand Down
13 changes: 10 additions & 3 deletions interop-cats/shared/src/main/scala/zio/interop/catszmanaged.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ trait CatsZManagedInstances extends CatsZManagedInstances1 {
override def combine(x: ZManaged[R, E, A], y: ZManaged[R, E, A]): ZManaged[R, E, A] = x.zipWith(y)(ev.combine)
}

implicit def arrowChoiceZManagedInstances[E]: ArrowChoice[ZManaged[*, E, *]] =
CatsZManagedArrowChoice.asInstanceOf[ArrowChoice[ZManaged[*, E, *]]]
implicit def arrowChoiceRManagedInstances[E]: ArrowChoice[RManaged] =
CatsZManagedArrowChoice.asInstanceOf[ArrowChoice[RManaged]]
}

sealed trait CatsZManagedInstances1 {
sealed trait CatsZManagedInstances1 extends CatsZManagedInstances2 {

implicit def monadZManagedInstances[R, E]: Monad[ZManaged[R, E, ?]] = new CatsZManagedMonad

Expand All @@ -138,6 +138,13 @@ sealed trait CatsZManagedInstances1 {
fab.mapError(f).map(g)
}

implicit def arrowChoiceURManagedInstances[E]: ArrowChoice[URManaged] =
CatsZManagedArrowChoice.asInstanceOf[ArrowChoice[URManaged]]
}

sealed trait CatsZManagedInstances2 {
implicit def arrowChoiceZManagedInstances[E]: ArrowChoice[ZManaged[*, E, *]] =
CatsZManagedArrowChoice.asInstanceOf[ArrowChoice[ZManaged[*, E, *]]]
}

private class CatsZManagedMonad[R, E] extends Monad[ZManaged[R, E, ?]] {
Expand Down
6 changes: 6 additions & 0 deletions interop-cats/shared/src/test/scala/zio/interop/catzSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package zio.interop

import cats.arrow.ArrowChoice
import cats.effect.concurrent.Deferred
import cats.effect.laws.discipline.arbitrary._
import cats.effect.laws.discipline.{ ConcurrentEffectTests, ConcurrentTests, EffectTests, SyncTests }
Expand Down Expand Up @@ -80,6 +81,11 @@ class catzSpec extends catzSpecZIOBase {

def concurrentEffect[R: Runtime] = ConcurrentEffect[RIO[R, *]]
def effect[R: Runtime] = Effect[RIO[R, *]]

// related to issue #173
def getArrow[F[-_, +_, +_], R, E, A](f: F[R, E, A])(implicit a: ArrowChoice[F[*, E, *]]): Any = (a, f)
getArrow(ZIO.environment[Int])
getArrow(ZManaged.environment[Int])
}

object summoningRuntimeInstancesTest {
Expand Down

0 comments on commit f58ade9

Please sign in to comment.