Skip to content

Instantly share code, notes, and snippets.

@wsargent
Forked from tpolecat/gist:8812750
Created February 8, 2014 05:54
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 wsargent/8877238 to your computer and use it in GitHub Desktop.
Save wsargent/8877238 to your computer and use it in GitHub Desktop.

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(
  "-deprecation",           
  "-encoding", "UTF-8",       // yes, this is 2 args
  "-feature",                
  "-language:existentials",
  "-language:experimental.macros",
  "-language:higherKinds",
  "-language:implicitConversions",
  "-unchecked",
  "-Xfatal-warnings",       
  "-Xlint",
  "-Yno-adapted-args",       
  "-Ywarn-all",             
  "-Ywarn-dead-code",        // N.B. doesn't work well with the ??? hole
  "-Ywarn-numeric-widen",   
  "-Ywarn-value-discard"     
)

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