Skip to content

Instantly share code, notes, and snippets.

@etorreborre
Last active November 3, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etorreborre/8929398 to your computer and use it in GitHub Desktop.
Save etorreborre/8929398 to your computer and use it in GitHub Desktop.
Why is WartRemover or -Ywarn-value-discard useful?
/**
* Can you spot the bug?
*/
var result = Result.ok("ok")
val processLogger = ProcessLogger(out => result = Result.ok(out), err => Result.fail("Error! "+err))
Process(Seq("sh", "-c", cmd), None, env.toSeq:_*) ! processLogger
result
/**
* Answer: the result variable is not assigned in case of error
*/
val processLogger = ProcessLogger(out => result = Result.ok(out),
result = err => Result.fail("Error! "+err))
@Primetalk
Copy link

It seems that there is a minor misprint in the answer. It should read:

val processLogger = ProcessLogger(
  out => result = Result.ok(out), 
  err => result = Result.fail("Error! "+err)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment