The Scala 3 scalac -source 3.1 option

If you ever need to use the Scala 3 -source option with scalac or the SBT build.sbt file, the correct syntax is:


It’s not clear from the scalac help text how the -source option should be used, and I just figured that out in my build.sbt file, which has these scalac options:

scalacOptions ++= Seq(
  "-deprecation",         // emit warning and location for usages of deprecated APIs
  "-explain",             // explain errors in more detail
  "-explain-types",       // explain type errors in more detail
  "-feature",             // emit warning and location for usages of features that should be imported explicitly
  "-indent",              // allow significant indentation.
  "-new-syntax",          // require `then` and `do` in control expressions.
  "-print-lines",         // show source code line numbers.
  "-unchecked",           // enable additional warnings where generated code depends on assumptions
  "-Ykind-projector",     // allow `*` as wildcard to be compatible with kind projector
  "-Xfatal-warnings",     // fail the compilation if there are any warnings
  "-Xmigration",          // warn about constructs whose behavior may have changed since version