Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
24 changes: 12 additions & 12 deletions core/shared/src/main/scala/zio/IsSubtype.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import scala.annotation.implicitNotFound
@implicitNotFound("\nThis operator requires that the output type be a subtype of ${B}\nBut the actual type was ${A}.")
sealed abstract class IsSubtypeOfOutput[-A, +B] extends (A => B) with Serializable
object IsSubtypeOfOutput {
implicit def impl[A, B](implicit subtype: A <:< B): IsSubtypeOfOutput[A, B] = new IsSubtypeOfOutput[A, B] {
override def apply(a: A): B = subtype(a)
}
private val instance: IsSubtypeOfOutput[Any, Any] = new IsSubtypeOfOutput[Any, Any] { def apply(a: Any): Any = a }

implicit def implNothing[B]: IsSubtypeOfOutput[Nothing, B] = new IsSubtypeOfOutput[Nothing, B] {
override def apply(a: Nothing): B = a
}
implicit def impl[A, B](implicit subtype: A <:< B): IsSubtypeOfOutput[A, B] =
instance.asInstanceOf[IsSubtypeOfOutput[A, B]]

implicit def implNothing[B]: IsSubtypeOfOutput[Nothing, B] =
instance.asInstanceOf[IsSubtypeOfOutput[Nothing, B]]
}

@implicitNotFound("\nThis operator requires that the error type be a subtype of ${B}\nBut the actual type was ${A}.")
sealed abstract class IsSubtypeOfError[-A, +B] extends (A => B) with Serializable
object IsSubtypeOfError {
implicit def impl[A, B](implicit subtype: A <:< B): IsSubtypeOfError[A, B] = new IsSubtypeOfError[A, B] {
override def apply(a: A): B = subtype(a)
}
private val instance: IsSubtypeOfError[Any, Any] = new IsSubtypeOfError[Any, Any] { def apply(a: Any): Any = a }

implicit def impl[A, B](implicit subtype: A <:< B): IsSubtypeOfError[A, B] =
instance.asInstanceOf[IsSubtypeOfError[A, B]]

implicit def implNothing[B]: IsSubtypeOfError[Nothing, B] = new IsSubtypeOfError[Nothing, B] {
override def apply(a: Nothing): B = a
}
implicit def implNothing[B]: IsSubtypeOfError[Nothing, B] =
instance.asInstanceOf[IsSubtypeOfError[Nothing, B]]
}
9 changes: 3 additions & 6 deletions core/shared/src/main/scala/zio/ZIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5494,15 +5494,12 @@ object ZIO extends ZIOCompanionPlatformSpecific with ZIOCompanionVersionSpecific
@implicitNotFound(
"Pattern guards are only supported when the error type is a supertype of NoSuchElementException. However, your effect has ${E} for the error type."
)
abstract class CanFilter[+E] {
sealed abstract class CanFilter[+E] {
def apply(t: NoSuchElementException): E
}

object CanFilter {
implicit def canFilter[E >: NoSuchElementException]: CanFilter[E] =
new CanFilter[E] {
def apply(t: NoSuchElementException): E = t
}
private val instance: CanFilter[Any] = new CanFilter[Any] { def apply(t: NoSuchElementException): Any = t }
implicit def canFilter[E >: NoSuchElementException]: CanFilter[E] = instance.asInstanceOf[CanFilter[E]]
}

final class Grafter(private val scope: FiberScope) extends AnyVal { self =>
Expand Down
7 changes: 4 additions & 3 deletions test/shared/src/main/scala-2/zio/test/Eql.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import scala.annotation.implicitNotFound
"they cannot be equal."
)
sealed abstract class Eql[A, B]

object Eql extends EqlLowPriority {
implicit final def eqlSubtype1[A <: B, B]: Eql[A, B] = new Eql[A, B] {}
implicit final def eqlSubtype1[A <: B, B]: Eql[A, B] = instance.asInstanceOf[Eql[A, B]]
}

private[test] sealed abstract class EqlLowPriority {
implicit final def eqlSubtype2[A, B <: A]: Eql[A, B] = new Eql[A, B] {}
protected val instance: Eql[Any, Any] = new Eql[Any, Any] {}

implicit final def eqlSubtype2[A, B <: A]: Eql[A, B] = instance.asInstanceOf[Eql[A, B]]
}
Loading