From 3abef46fdfa8a291d4efb0e6844e686742dc76f2 Mon Sep 17 00:00:00 2001 From: nomisRev Date: Fri, 17 May 2019 17:11:06 +0200 Subject: [PATCH] Unkown IOs always need to be wrapped in Async --- .../main/scala/cats/effect/internals/IORunLoop.scala | 12 ++++++++---- laws/shared/src/test/scala/cats/effect/IOTests.scala | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/shared/src/main/scala/cats/effect/internals/IORunLoop.scala b/core/shared/src/main/scala/cats/effect/internals/IORunLoop.scala index 504c52aad8..a300cbcb84 100644 --- a/core/shared/src/main/scala/cats/effect/internals/IORunLoop.scala +++ b/core/shared/src/main/scala/cats/effect/internals/IORunLoop.scala @@ -210,10 +210,14 @@ private[effect] object IORunLoop { bFirst = bindNext.asInstanceOf[Bind] currentIO = fa - case _ => + case Async(_, _) => // Cannot inline the code of this method — as it would // box those vars in scala.runtime.ObjectRef! - return suspendInAsync(currentIO.asInstanceOf[IO[A]], bFirst, bRest) + return suspendAsync(currentIO.asInstanceOf[IO.Async[A]], bFirst, bRest) + case _ => + return Async { (conn, cb) => + loop(currentIO, conn, cb.asInstanceOf[Callback], null, bFirst, bRest) + } } if (hasUnboxed) { @@ -234,8 +238,8 @@ private[effect] object IORunLoop { // $COVERAGE-ON$ } - private def suspendInAsync[A]( - currentIO: IO[A], + private def suspendAsync[A]( + currentIO: IO.Async[A], bFirst: Bind, bRest: CallStack): IO[A] = { diff --git a/laws/shared/src/test/scala/cats/effect/IOTests.scala b/laws/shared/src/test/scala/cats/effect/IOTests.scala index 63520e3725..1365cbb356 100644 --- a/laws/shared/src/test/scala/cats/effect/IOTests.scala +++ b/laws/shared/src/test/scala/cats/effect/IOTests.scala @@ -495,6 +495,11 @@ class IOTests extends BaseTestsSuite { io.unsafeRunSync() shouldEqual 2 } + test("uncancelable with unsafeRunSync") { + val io = IO.pure(1).uncancelable + io.unsafeRunSync() shouldBe 1 + } + test("map is stack-safe for unsafeRunSync") { import IOPlatform.{fusionMaxStackDepth => max} val f = (x: Int) => x + 1