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

False warnings with scalac-option -Wnonunit-statement #316

Closed
cornerman opened this issue Feb 2, 2023 · 2 comments
Closed

False warnings with scalac-option -Wnonunit-statement #316

cornerman opened this issue Feb 2, 2023 · 2 comments

Comments

@cornerman
Copy link

The scala-async macro does not work well together with the rather new scalac option -Wnonunit-statement (scala/scala#9893).

Example:

  def test(): Future[Boolean] =
    async {
      await(Future.successful(true))
    }

This will yield a warning:

unused value of type Boolean (add `: Unit` to discard silently)
[warn]     async {

Anything we can do about it?

@cornerman
Copy link
Author

This seems to be related how markForAsyncTransform work in the scala compiler. The above expression desugars into the following:

{
  final class stateMachine$async extends _root_.scala.async.FutureStateMachine {
    def <init>(): stateMachine$async = {
      stateMachine$async.super.<init>(scala.concurrent.ExecutionContext.Implicits.global);
      ()
    };
    override def apply(tr$async: scala.util.Try[AnyRef]): Unit = {
      scala.Predef.locally[Boolean](scala.async.Async.await[Boolean](scala.concurrent.Future.successful[Boolean](true)));
      ()
    }
  };
  (new stateMachine$async().start[Nothing](): scala.concurrent.Future[Boolean])
}

There we have an unused non-unit statement with the locally block which returns an unused Boolean.

@som-snytt
Copy link
Contributor

Fixed on the transform side, which is more general.

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
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