37

How can I find all of the flags for the latest scalac version? After googling for hours I have found only outdated docs. (for example, they don't even mention "-feature" flag).

Is there any way to obtain the list of compiler flags with descriptions from scalac, or anything else?

Michael Zajac
  • 55,144
  • 7
  • 113
  • 138
Jeriho
  • 7,129
  • 9
  • 41
  • 57

3 Answers3

30

Edit: Documentation for Scala Compiler Options has been posted.

Most of us get by with scalac -help, scalac -X and scalac -Y.

Don't forget to scala -help, too.

Edit: sbt user can do the usual:

> set scalacOptions in Compile += "-X"
> compile
[snip]
[info]   -Xcheck-null                   Warn upon selection of nullable reference.
[info]   -Xcheckinit                    Wrap field accessors to throw an exception on uninitialized access.
[info]   -Xdisable-assertions           Generate no assertions or assumptions.
[info]   -Xdivergence211                Turn on the 2.11 behavior of implicit divergence not terminating recursive implicit searches (SI-7291).
[info]   -Xelide-below <n>              Calls to @elidable methods are omitted if method priority is lower than argument
[info]   -Xexperimental                 Enable experimental extensions.
[info]   -Xfatal-warnings               Fail the compilation if there are any warnings.
[snip]

At least the man page was updated recently:

https://issues.scala-lang.org/browse/SI-7824

som-snytt
  • 39,429
  • 2
  • 47
  • 129
  • 6
    If the majority of your Scala usage is through Maven or SBT, you may not actually have scalac installed on your system (I don't), so this is not always the most convenient solution. Real online documentation of the compiler would be very useful. – Christopher Currie Sep 08 '13 at 07:48
  • 1
    @ChristopherCurrie I agree it's annoying that the doc/tools doesn't show latest basic options for `scalac`. I think I'll open a ticket if there isn't one; that should be automated. I even just said to myself, where's `feature` and `language` as did the OP. "D'oh." – som-snytt Sep 09 '13 at 04:08
  • 1
    This is also annoying if you're working with a build that uses a different version of scalac from what you have installed locally. – stewSquared Jul 30 '18 at 21:12
  • 1
    Also strange approach: Scala 2.12.12 doesn't have support for JMV>8 in scalacOptions, despite https://docs.scala-lang.org/overviews/compiler-options/index.html saying opposite.

    [error] Usage: -target: where choices are jvm-1.5, jvm-1.6, jvm-1.7, jvm-1.8 (default: jvm-1.8). vs

    docs: -target:TARGET or --target:TARGET Target platform for object files. ([8],9,10,11,12)

    – Donald Duck Nov 19 '20 at 12:25
  • 1
    @DonaldDuck it seems I commented that it should have a drop-down to select a version. Maybe I'll break that request out into a new ticket. https://github.com/scala/docs.scala-lang/issues/1711#issuecomment-628347181 – som-snytt Nov 21 '20 at 19:46
27

The closest I have been able to find is the relevant source files for the compiler. Unfortunately the options are spread among several files. As of this writing, it breaks down like so:

These will of course be for the current development version of the compiler, so if you want options for a specific version of scalac, you'll need to use the "branch" drop-down menu to view the correct version tag.

Michael Zajac
  • 55,144
  • 7
  • 113
  • 138
Christopher Currie
  • 3,025
  • 1
  • 29
  • 40
  • Another idea is to grab the source and `ant docs.comp`. Then scala/build/scaladoc/compiler/index.html#scala.tools.nsc.Settings inherits from std and other settings. Unfortunately, the scaladoc is only a listing. Another idea is to grab the Eclipse IDE and browse those sources that way. – som-snytt Sep 09 '13 at 05:00
  • another fairly fresh list of arguments and definitions: https://tpolecat.github.io/2017/04/25/scalac-flags.html – Andrew Norman Mar 23 '18 at 17:53
0

Since Dotty (Scala 3), it seems these options are in a different place.

Sadly it seems that the language flags no longer show up when typing scalac -language:help like it does for 2.13.8, not sure why.

I believe those are all the prominent options for Dotty.

Jaacko Torus
  • 796
  • 7
  • 24