Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
swoogles opened this issue Apr 11, 2023 · 2 comments
Open

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

swoogles opened this issue Apr 11, 2023 · 2 comments

Comments

@swoogles
Copy link
Contributor

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
Copy link
Contributor Author

swoogles commented May 8, 2023

@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.

@deusaquilus
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants