David's Blog

Enable Scala compiler warnings on value discarding behavior

Most of my coding at work these days is done in Scala. Overall I think there's a lot to like in the particular subset of the language/style that we use but there are a few pet peeves that I have and value discarding is one of those. It's particularly insidious when paired with futures. There's probably a longer post in me about this topic but for now I thought I'd share something I learned this week for surfacing this behavior to make users aware of it.

It turns out that there's not a way to disable value discarding in Scala but there is a way to make the compiler emit a warning when it uses this language feature. The compiler flags "-Ywarn-value-discard" or "-Wvalue-discard" will enable those warnings.

If desired, one way you can sort of "disable" value discarding is by making compiler warnings fatal but that has to be done at a global level; you can't enable that only for the value discarding warning flag.