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

defer blocks discarding unit effects #903

Open
johnhungerford opened this issue Dec 5, 2024 · 4 comments
Open

defer blocks discarding unit effects #903

johnhungerford opened this issue Dec 5, 2024 · 4 comments
Labels
💎 Bounty bug Something isn't working

Comments

@johnhungerford
Copy link
Contributor

Minimized example

import kyo.*

def runInner: Unit < Async = defer:
  await(Console.println("test"))

@main def main(): Unit =
  import AllowUnsafe.embrace.danger
  val _ =  KyoApp.Unsafe.runAndBlock(Duration.Infinity)(runInner)

scalac options in build.sbt:

scalacOptions ++= Seq(
  "-Wvalue-discard", 
  "-Wnonunit-statement", 
  "-Wconf:msg=(discarded.*value|pure.*statement):error",
),

Expected result

Should cause compiler error: discarded non-Unit value of type Unit < (kyo.IO & kyo.Abort[java.io.IOException]) (If the defer block in runInner is replaced with a direct call to Console.println, this is what happens)

Actual result

No compiler error or warnings, and the application runs without displaying anything message

@johnhungerford
Copy link
Contributor Author

johnhungerford commented Dec 5, 2024

Workaround: annotating runInner as Any < ... will cause the compiler to catch the error. It seems to be a problem only for unit values. Anyone working with kyo-direct might consider using Any in place of Unit until some solution is found.

@hearnadam hearnadam added the bug Something isn't working label Jan 4, 2025
@fwbrasil
Copy link
Collaborator

/bounty 100

Copy link

algora-pbc bot commented Jan 23, 2025

💎 $100 bounty • Kyo

Steps to solve:

  1. Start working: Comment /attempt #903 with your implementation plan
  2. Submit work: Create a pull request including /claim #903 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to getkyo/kyo!

Add a bountyShare on socials

@fwbrasil
Copy link
Collaborator

I took a look at this and couldn't find a way to fix it. It seems the compiler just bypasses the check. cc/ @rssh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants