scala/scala-async

Compiler warns about "pure expression does nothing in statement position"

orium opened this issue · 4 comments

orium commented

If you have a future foo: Future[Unit] and do a await(foo) the compiler will give a warning:

Warning:(258, 16) a pure expression does nothing in statement position; you may be omitting necessary parentheses
          await(foo)
               ^

Edit: This does not happen in all awaits on Future[Unit]s, as I initially assumed. Below is the minimal code I could get that reproduces this:

def foo(foobaz: Future[Unit]) =
  async {
    if ("".isEmpty) {
      await(foobaz)
      0
    }
  }

+1

In scala 2.11, I get a very similar error message for

def checkForException(codeBlock: Any, finallyBlock: Any = ()): Any = {
    try {
      codeBlock
    } catch {
      ...
    } finally {
      finallyBlock
    }
  }

the warning is:

a pure expression does nothing in statement position; you may be omitting necessary parentheses
[warn] finallyBlock

Update: I fixed my warning by changing the function signature to be:
def checkForException(codeBlock: => Unit, finallyBlock: => Unit = ()): Any