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
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/cats/effect/Bracket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ object ExitCase {
* outcome for the user, but it does for the purposes of the
* `bracket` operation.
*/
final case object Completed extends ExitCase[Nothing]
case object Completed extends ExitCase[Nothing]

/**
* An [[ExitCase]] signaling completion in failure.
Expand All @@ -209,7 +209,7 @@ object ExitCase {
* Thus [[Bracket]] allows you to observe interruption conditions
* and act on them.
*/
final case object Canceled extends ExitCase[Nothing]
case object Canceled extends ExitCase[Nothing]

/**
* Parametrized alias for the [[Completed]] data constructor.
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ object IO extends IOInstances {
* into the `IO`.
*/
def delay[A](body: => A): IO[A] =
Delay(body _)
Delay(() => body)

/**
* Suspends a synchronous side effect which produces an `IO` in `IO`.
Expand All @@ -1062,7 +1062,7 @@ object IO extends IOInstances {
* `IO`.
*/
def suspend[A](thunk: => IO[A]): IO[A] =
Suspend(thunk _)
Suspend(() => thunk)

/**
* Suspends a pure value in `IO`.
Expand Down
8 changes: 4 additions & 4 deletions core/shared/src/main/scala/cats/effect/SyncEffect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ object SyncEffect {
* [[SyncEffect]] instance built for `cats.data.EitherT` values initialized
* with any `F` data type that also implements `SyncEffect`.
*/
implicit def catsEitherTSyncEffect[F[_]: SyncEffect]: SyncEffect[EitherT[F, Throwable, ?]] =
implicit def catsEitherTSyncEffect[F[_]: SyncEffect]: SyncEffect[EitherT[F, Throwable, *]] =
new EitherTSyncEffect[F] { def F = SyncEffect[F] }

/**
* [[SyncEffect]] instance built for `cats.data.WriterT` values initialized
* with any `F` data type that also implements `SyncEffect`.
*/
implicit def catsWriterTSyncEffect[F[_]: SyncEffect, L: Monoid]: SyncEffect[WriterT[F, L, ?]] =
implicit def catsWriterTSyncEffect[F[_]: SyncEffect, L: Monoid]: SyncEffect[WriterT[F, L, *]] =
new WriterTSyncEffect[F, L] { def F = SyncEffect[F]; def L = Monoid[L] }

private[effect] trait EitherTSyncEffect[F[_]]
extends SyncEffect[EitherT[F, Throwable, ?]]
extends SyncEffect[EitherT[F, Throwable, *]]
with Sync.EitherTSync[F, Throwable] {
protected def F: SyncEffect[F]

def runSync[G[_], A](fa: EitherT[F, Throwable, A])(implicit G: Sync[G]): G[A] =
F.runSync(F.rethrow(fa.value))
}

private[effect] trait WriterTSyncEffect[F[_], L] extends SyncEffect[WriterT[F, L, ?]] with Sync.WriterTSync[F, L] {
private[effect] trait WriterTSyncEffect[F[_], L] extends SyncEffect[WriterT[F, L, *]] with Sync.WriterTSync[F, L] {
protected def F: SyncEffect[F]
protected def L: Monoid[L]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ object Ref {
override def modifyState[B](state: State[A, B]): G[B] = trans(underlying.modifyState(state))

override def access: G[(A, A => G[Boolean])] =
trans(F.compose[(A, ?)].compose[A => *].map(underlying.access)(trans(_)))
trans(F.compose[(A, *)].compose[A => *].map(underlying.access)(trans(_)))
}

implicit def catsInvariantForRef[F[_]: Functor]: Invariant[Ref[F, *]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ private[effect] object IOBracket {
private def applyRelease(e: ExitCase[Throwable]): IO[Unit] =
IO.suspend {
if (waitsForResult.compareAndSet(true, false))
release(e).redeemWith(ex => IO(p.success(())).flatMap(_ => IO.raiseError(ex)), _ => IO(p.success(())))
release(e)
.redeemWith[Unit](ex => IO(p.success(())).flatMap(_ => IO.raiseError(ex)), _ => IO { p.success(()); () })
else
IOFromFuture.apply(p.future)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private[effect] object IOConnection {
case list =>
CancelUtils
.cancelAll(list.iterator)
.redeemWith(ex => IO(p.success(())).flatMap(_ => IO.raiseError(ex)), _ => IO(p.success(())))
.redeemWith(ex => IO(p.success(())).flatMap(_ => IO.raiseError(ex)), _ => IO { p.success(()); () })
}
}

Expand Down
20 changes: 12 additions & 8 deletions core/shared/src/main/scala/cats/effect/internals/IORunLoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private[effect] object IORunLoop {
// For auto-cancellation
var currentIndex = 0

do {
while ({
currentIO match {
case Bind(fa, bindNext) =>
if (bFirst ne null) {
Expand Down Expand Up @@ -154,7 +154,8 @@ private[effect] object IORunLoop {
if (conn.isCanceled) return
currentIndex = 0
}
} while (true)
true
}) ()
}

/**
Expand All @@ -170,7 +171,7 @@ private[effect] object IORunLoop {
var hasUnboxed: Boolean = false
var unboxed: AnyRef = null

do {
while ({
currentIO match {
case Bind(fa, bindNext) =>
if (bFirst ne null) {
Expand Down Expand Up @@ -241,7 +242,8 @@ private[effect] object IORunLoop {
bFirst = null
}
}
} while (true)
true
}) ()
// $COVERAGE-OFF$
null // Unreachable code
// $COVERAGE-ON$
Expand All @@ -267,14 +269,15 @@ private[effect] object IORunLoop {
return bFirst

if (bRest eq null) return null
do {
while ({
val next = bRest.pop()
if (next eq null) {
return null
} else if (!next.isInstanceOf[IOFrame.ErrorHandler[_]]) {
return next
}
} while (true)
true
}) ()
// $COVERAGE-OFF$
null
// $COVERAGE-ON$
Expand All @@ -290,13 +293,14 @@ private[effect] object IORunLoop {
case _ =>
if (bRest eq null) null
else {
do {
while ({
val ref = bRest.pop()
if (ref eq null)
return null
else if (ref.isInstanceOf[IOFrame[_, _]])
return ref.asInstanceOf[IOFrame[Any, IO[Any]]]
} while (true)
true
}) ()
// $COVERAGE-OFF$
null
// $COVERAGE-ON$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private[effect] object IOStart {
// Starting the source `IO`, with a new connection, because its
// cancellation is now decoupled from our current one
val conn2 = IOConnection()
val cb0 = { ea: Either[Throwable, A] =>
val cb0 = { (ea: Either[Throwable, A]) =>
p.success(ea)
()
}
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/test/scala/cats/effect/AsyncTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AsyncTests extends AsyncFunSuite with Matchers {
private def awaitEqual[A: Eq](t: IO[A], success: A): IO[Unit] =
t.flatMap(a => if (Eq[A].eqv(a, success)) IO.unit else smallDelay *> awaitEqual(t, success))

private def run(t: IO[Unit]): Future[Assertion] = t.as(Succeeded).unsafeToFuture
private def run(t: IO[Unit]): Future[Assertion] = t.as(Succeeded).unsafeToFuture()

test("F.parTraverseN(n)(collection)(f)") {
val finalValue = 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ConcurrentTests extends AsyncFunSuite with Matchers {
private def awaitEqual[A: Eq](t: IO[A], success: A): IO[Unit] =
t.flatMap(a => if (Eq[A].eqv(a, success)) IO.unit else smallDelay *> awaitEqual(t, success))

private def run(t: IO[Unit]): Future[Assertion] = t.as(Succeeded).unsafeToFuture
private def run(t: IO[Unit]): Future[Assertion] = t.as(Succeeded).unsafeToFuture()

test("F.parTraverseN(n)(collection)(f)") {
val finalValue = 100
Expand Down
9 changes: 4 additions & 5 deletions core/shared/src/test/scala/cats/effect/IOAppTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ package effect

import scala.concurrent.ExecutionContext
import cats.effect.internals.{IOAppPlatform, TestUtils, TrampolineEC}
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.funsuite.AsyncFunSuite

class IOAppTests extends AsyncFunSuite with Matchers with BeforeAndAfterAll with TestUtils {
class IOAppTests extends AsyncFunSuite with Matchers with TestUtils {
test("exits with specified code") {
IOAppPlatform
.mainFiber(Array.empty, Eval.now(implicitly[ContextShift[IO]]), Eval.now(implicitly[Timer[IO]]))(
_ => IO.pure(ExitCode(42))
)
.flatMap(_.join)
.unsafeToFuture
.unsafeToFuture()
.map(_ shouldEqual 42)
}

Expand All @@ -40,7 +39,7 @@ class IOAppTests extends AsyncFunSuite with Matchers with BeforeAndAfterAll with
args => IO.pure(ExitCode(args.mkString.toInt))
)
.flatMap(_.join)
.unsafeToFuture
.unsafeToFuture()
.map(_ shouldEqual 123)
}

Expand All @@ -49,7 +48,7 @@ class IOAppTests extends AsyncFunSuite with Matchers with BeforeAndAfterAll with
IOAppPlatform
.mainFiber(Array.empty, Eval.now(implicitly), Eval.now(implicitly))(_ => IO.raiseError(new Exception()))
.flatMap(_.join)
.unsafeToFuture
.unsafeToFuture()
.map(_ shouldEqual 1)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/test/scala/cats/effect/SyntaxTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object SyntaxTests extends AllCatsEffectSyntax {
val _ = a
}

def bracketSyntax[F[_]: Bracket[?[_], Throwable], A, B] = {
def bracketSyntax[F[_], A, B](implicit F: Bracket[F, Throwable]) = {
val acquire = mock[F[A]]
val use = mock[A => F[B]]
val releaseCase = mock[(A, ExitCase[Throwable]) => F[Unit]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DeferredTests extends AsyncFunSuite with Matchers {
.flatMap { p =>
p.complete(0) *> p.get
}
.unsafeToFuture
.unsafeToFuture()
.map(_ shouldBe 0)
}

Expand All @@ -48,7 +48,7 @@ class DeferredTests extends AsyncFunSuite with Matchers {
.flatMap { p =>
(p.complete(0) *> p.complete(1).attempt).product(p.get)
}
.unsafeToFuture
.unsafeToFuture()
.map {
case (err, value) =>
err.swap.toOption.get shouldBe an[IllegalStateException]
Expand All @@ -66,13 +66,13 @@ class DeferredTests extends AsyncFunSuite with Matchers {
_ <- readGate.get
res <- state.get
} yield res
op.unsafeToFuture.map(_ shouldBe 2)
op.unsafeToFuture().map(_ shouldBe 2)
}
}

def tryableTests(label: String, pc: TryableDeferredConstructor): Unit = {
test(s"$label - tryGet returns None for unset Deferred") {
pc[Unit].flatMap(_.tryGet).unsafeToFuture.map(_ shouldBe None)
pc[Unit].flatMap(_.tryGet).unsafeToFuture().map(_ shouldBe None)
}

test(s"$label - tryGet returns Some() for set Deferred") {
Expand All @@ -82,7 +82,7 @@ class DeferredTests extends AsyncFunSuite with Matchers {
result <- d.tryGet
} yield result shouldBe Some(())

op.unsafeToFuture
op.unsafeToFuture()
}
}

Expand All @@ -108,7 +108,7 @@ class DeferredTests extends AsyncFunSuite with Matchers {
} yield result

test("concurrent - get - cancel before forcing") {
cancelBeforeForcing(Deferred.apply).unsafeToFuture.map(_ shouldBe None)
cancelBeforeForcing(Deferred.apply).unsafeToFuture().map(_ shouldBe None)
}

test("issue #380: complete doesn't block, test #1") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import org.scalatestplus.scalacheck.Checkers

class ExitCodeTests extends AnyFunSuite with Matchers with Checkers {
test("fromInt(i) == fromInt(i & 0xff)") {
check { i: Int =>
check { (i: Int) =>
ExitCode(i) == ExitCode(i & 0xff)
}
}

test("code is in range from 0 to 255, inclusive") {
check { i: Int =>
check { (i: Int) =>
val ec = ExitCode(i)
ec.code >= 0 && ec.code < 256
}
Expand Down
18 changes: 9 additions & 9 deletions core/shared/src/test/scala/cats/effect/concurrent/RefTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RefTests extends AsyncFunSuite with Matchers {
private def awaitEqual[A: Eq](t: IO[A], success: A): IO[Unit] =
t.flatMap(a => if (Eq[A].eqv(a, success)) IO.unit else smallDelay *> awaitEqual(t, success))

private def run(t: IO[Unit]): Future[Assertion] = t.as(Succeeded).unsafeToFuture
private def run(t: IO[Unit]): Future[Assertion] = t.as(Succeeded).unsafeToFuture()

test("concurrent modifications") {
val finalValue = 100
Expand All @@ -53,7 +53,7 @@ class RefTests extends AsyncFunSuite with Matchers {
getResult <- r.get
} yield getAndSetResult == 0 && getResult == 1

run(op.map(_ shouldBe true))
run(op.map(_ shouldBe true).void)
}

test("access - successful") {
Expand All @@ -64,7 +64,7 @@ class RefTests extends AsyncFunSuite with Matchers {
success <- setter(value + 1)
result <- r.get
} yield success && result == 1
run(op.map(_ shouldBe true))
run(op.map(_ shouldBe true).void)
}

test("access - setter should fail if value is modified before setter is called") {
Expand All @@ -76,7 +76,7 @@ class RefTests extends AsyncFunSuite with Matchers {
success <- setter(value + 1)
result <- r.get
} yield !success && result == 5
run(op.map(_ shouldBe true))
run(op.map(_ shouldBe true).void)
}

test("access - setter should fail if called twice") {
Expand All @@ -89,7 +89,7 @@ class RefTests extends AsyncFunSuite with Matchers {
cond2 <- setter(value + 1)
result <- r.get
} yield cond1 && !cond2 && result == 0
run(op.map(_ shouldBe true))
run(op.map(_ shouldBe true).void)
}

test("tryUpdate - modification occurs successfully") {
Expand All @@ -99,7 +99,7 @@ class RefTests extends AsyncFunSuite with Matchers {
value <- r.get
} yield result && value == 1

run(op.map(_ shouldBe true))
run(op.map(_ shouldBe true).void)
}

test("tryUpdate - should fail to update if modification has occurred") {
Expand All @@ -115,7 +115,7 @@ class RefTests extends AsyncFunSuite with Matchers {
)
} yield result

run(op.map(_ shouldBe false))
run(op.map(_ shouldBe false).void)
}

test("tryModifyState - modification occurs successfully") {
Expand All @@ -124,7 +124,7 @@ class RefTests extends AsyncFunSuite with Matchers {
result <- r.tryModifyState(State.pure(1))
} yield result.contains(1)

run(op.map(_ shouldBe true))
run(op.map(_ shouldBe true).void)
}

test("modifyState - modification occurs successfully") {
Expand All @@ -133,6 +133,6 @@ class RefTests extends AsyncFunSuite with Matchers {
result <- r.modifyState(State.pure(1))
} yield result == 1

run(op.map(_ shouldBe true))
run(op.map(_ shouldBe true).void)
}
}
Loading