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

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

Closed
orium opened this issue Apr 11, 2016 · 4 comments · Fixed by #237
Closed

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

orium opened this issue Apr 11, 2016 · 4 comments · Fixed by #237
Milestone

Comments

@orium
Copy link

orium commented Apr 11, 2016

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
    }
  }
@vtsaplin
Copy link

vtsaplin commented Nov 6, 2016

+1

1 similar comment
@lmatshoba
Copy link

+1

@barrybecker4
Copy link

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

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

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

Successfully merging a pull request may close this issue.

5 participants