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 await
s 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
}
}
vtsaplin commented
+1
lmatshoba commented
+1
barrybecker4 commented
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
barrybecker4 commented
Update: I fixed my warning by changing the function signature to be:
def checkForException(codeBlock: => Unit, finallyBlock: => Unit = ()): Any