Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Useful Scalac Flags

So, there have been some discussions and angry tweets recently about irritating Scala "features" (like value discarding and auto-tupling) that can actually be turned off by selecting the right compiler flag in conjunction with -Xfatal-warnings. I highly recommend a set of options something like those below.

scalacOptions ++= Seq(
  "-encoding", "UTF-8",       // yes, this is 2 args
  "-Ywarn-dead-code",        // N.B. doesn't work well with the ??? hole

I also recommend keeping an eye on warteremover which casts a wider net and disables many other unsafe features such as null and return. If you try it out and find it's hitting false positives (generally with synthetic code) please file a bug report. We're working on it!

UPDATE - Sukant Hajra has more energy than I do and finally got to the bottom of the -Xlint and -Ywarn-all flags and found that although they are not the same from version to version, they are identical, which is probably a copy/paste bug. Here's the relevant code from 2.9.3 and 2.10.3 if you want to see for yourself.

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