Skip to content

Commit

Permalink
[core][stm] fix compilation warning with Scala 3.6 + add AllowUnsafe …
Browse files Browse the repository at this point in the history
…to evalOrThrow (#923)
  • Loading branch information
fwbrasil authored Dec 12, 2024
1 parent 8cc15d0 commit 6ace1ab
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion kyo-core/shared/src/main/scala/kyo/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ object IO:
* @throws Throwable
* If the evaluation results in an error
*/
def evalOrThrow[A: Flat](v: A < (IO & Abort[Throwable]))(using Frame): A =
def evalOrThrow[A: Flat](v: A < (IO & Abort[Throwable]))(using Frame, AllowUnsafe): A =
Abort.run(v).eval.getOrThrow

/** Runs an IO effect, evaluating it and its side effects.
Expand Down
1 change: 1 addition & 0 deletions kyo-core/shared/src/test/scala/kyo/IOTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class IOTest extends Test:
}

"evalOrThrow" - {
import AllowUnsafe.embrace.danger
"success" in run {
val result = IO.Unsafe.evalOrThrow(IO(42))
assert(result == 42)
Expand Down
13 changes: 8 additions & 5 deletions kyo-core/shared/src/test/scala/kyo/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ abstract class Test extends AsyncFreeSpec with BaseKyoTest[Abort[Any] & Async &

def run(v: Future[Assertion] < (Abort[Any] & Async & Resource)): Future[Assertion] =
import AllowUnsafe.embrace.danger
val a = Async.run(Abort.run(Resource.run(v)).map(_.fold {
_.getFailure match
v.pipe(
Resource.run,
Abort.recover[Any] {
case ex: Throwable => throw ex
case e => throw new IllegalStateException(s"Test aborted with $e")
}(identity)))
val b = a.map(_.toFuture).map(_.flatten)
IO.Unsafe.evalOrThrow(b)
},
Async.run,
_.map(_.toFuture).map(_.flatten),
IO.Unsafe.evalOrThrow
)
end run

type Assertion = org.scalatest.compatible.Assertion
Expand Down
13 changes: 8 additions & 5 deletions kyo-stm/shared/src/test/scala/kyo/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ abstract class Test extends AsyncFreeSpec with BaseKyoTest[Abort[Any] & Async &

def run(v: Future[Assertion] < (Abort[Any] & Async & Resource)): Future[Assertion] =
import AllowUnsafe.embrace.danger
val a = Async.run(Abort.run(Resource.run(v)).map(_.fold {
_.getFailure match
v.pipe(
Resource.run,
Abort.recover[Any] {
case ex: Throwable => throw ex
case e => throw new IllegalStateException(s"Test aborted with $e")
}(identity)))
val b = a.map(_.toFuture).map(_.flatten)
IO.Unsafe.evalOrThrow(b)
},
Async.run,
_.map(_.toFuture).map(_.flatten),
IO.Unsafe.evalOrThrow
)
end run

type Assertion = org.scalatest.compatible.Assertion
Expand Down

0 comments on commit 6ace1ab

Please sign in to comment.