zio-direct icon indicating copy to clipboard operation
zio-direct copied to clipboard

Surprising behavior when converting ZIO[_, _, Nothing]

Open swoogles opened this issue 1 year ago • 2 comments

I was converting some code:

val oldStyle =
  for 
    _ <- printLine("Hi")
    _ <- ZIO.fail("Error!")
  yield ()

into

val directStyle =
  defer {
    printLine("Hi").run
    ZIO.fail("Error!").run
  }

and got this error message:

missing arguments for method apply in trait deferCall
  defer {

Is there a fundamental reason why we cannot return ZIOs with a Nothing result inside defer blocks? If so, is there a way we could provide better error messages in this situation? There are some great custom compilation error messages in this library, so I was surprised when I hit this one. It took me a while to figure out what was actually causing the problem.

swoogles avatar Apr 11 '23 03:04 swoogles

@deusaquilus This tripped me up again while working on a demonstration of how to react to a long running process.

object ReportLongRunning extends ZIOAppDefault:

  val longRunning = defer {
    ZIO.sleep(5.seconds).run
    ZIO.debug("Finished long-running process").run
  }
  val reportLongRunning = defer {
    ZIO.sleep(3.seconds).run
    ZIO.debug("This is taking a while...").run
    ZIO.never.run
  }

  def run =
    longRunning.race(reportLongRunning)

Same error, so nothing really novel. It just made me realize that tricks around racing against aZIO.never aren't possible currently.

swoogles avatar May 08 '23 03:05 swoogles

I ran into this issue a couple of times too but I don't know what the problem is yet. I think it has to do with the overloaded variants of defer.

deusaquilus avatar Aug 08 '23 20:08 deusaquilus