This doc page is specific to features shipped in Scala 2, which have either been removed in Scala 3 or replaced by an alternative. Unless otherwise stated, all the code examples in this page assume you are using Scala 2.
Introduction
The Scala compiler scalac
offers various compiler options, or flags, that change the compiler’s default behavior. Some options just generate more compiler output in the form of diagnostics or warnings, while others change the result of compilation.
The Scala command scala
, which runs scripts or compiled code, accepts the same options as the scalac
compiler, plus a few more that determine how to run a program.
Options may be specified on the command line to scalac
or in the configuration of a build tool or IDE.
The Scala distribution includes a man
page. If Scala is installed as a system command, that documentation may be available from man scalac
.
How to use compiler options
Use compiler options with scalac
scalac [ <options> ] <source files>
Boolean flags are specified in the usual way:
scalac -Werror -Xlint Hello.scala
Options that require arguments use “colon” syntax:
scalac -Vprint:parser,typer
Options that take just a single argument accept traditional syntax:
scalac -d /tmp
Conventionally, options have a prefix -V
if they show “verbose” output;
-W
to manage warnings; -X
for extended options that modify tool behavior;
-Y
for private options with limited support, where Y
may suggest forking behavior.
Several options have historical aliases, such as -Xfatal-warnings
for -Werror
.
In Scala 2, default paths can be listed by running a tool in the distribution:
scala scala.tools.util.PathResolver [ <options> ]
That can help debug errors in options such as --classpath
.
Use compiler options with sbt
Here is a typical configuration of the scalacOptions
setting in sbt
:
scalacOptions ++= Seq( // use ++= to add to existing options
"-encoding", "utf8", // if an option takes an arg, supply it on the same line
"-feature", // then put the next option on a new line for easy editing
"-language:implicitConversions",
"-language:existentials",
"-unchecked",
"-Werror",
"-Xlint", // exploit "trailing comma" syntax so you can add an option without editing this line
) // for "trailing comma", the closing paren must be on the next line
The convention is always to append to the setting with ++=
and to supply one option per line.
Normally the last option will have a trailing comma so that git diff
is a bit cleaner when options are added.
Standard Settings
A set of standard options that are supported on the current development environment and will be supported in future releases.
-
-Dproperty=value
-
Pass -Dproperty=value directly to the runtime system.
-
-J<flag>
-
Pass flag directly to the runtime system.
-
-P PLUGIN:OPT1,PLUGIN:OPT2
-
Pass an option to a plugin
-
-V
-
Print a synopsis of verbose options.
-
-W
-
Print a synopsis of warning options.
-
-Werror
or-Xfatal-warnings
-
Fail the compilation if there are any warnings.
-
-X
-
Print a synopsis of advanced options.
-
-Y
-
Print a synopsis of private options.
-
-bootclasspath PATH
or--boot-class-path PATH
-
Override location of bootstrap class files.
-
-classpath PATH
or-cp PATH
or--class-path PATH
-
Specify where to find user class files.
Default:.
-
-d DIRECTORY|JAR
-
destination for generated classfiles.
Default:.
-
-dependencyfile FILE
or--dependency-file FILE
-
Set dependency tracking file.
Default:.scala_dependencies
-
-deprecation
or--deprecation
-
Emit warning and location for usages of deprecated APIs.
-
-encoding ENCODING
or--encoding ENCODING
-
Specify character encoding used by source files.
Default:UTF-8
-
-explaintypes
or--explain-types
-
Explain type errors in more detail.
-
-extdirs PATH
or--extension-directories PATH
-
Override location of installed extensions.
-
-feature
or--feature
-
Emit warning and location for usages of features that should be imported explicitly.
-
-g:LEVEL
-
Set level of generated debugging info. (none,source,line,[vars],notailcalls)
Default:vars
-
-g:none
-g:source
-g:line
-g:vars
-g:notailcalls
-
-help
or--help
-
Print a synopsis of standard options
-
-javabootclasspath PATH
or--java-boot-class-path PATH
-
Override java boot classpath.
Default:
-
-javaextdirs PATH
or--java-extension-directories PATH
-
Override java extdirs classpath.
-
-language:FEATURE1,FEATURE2
or--language:FEATURE1,FEATURE2
-
Enable or disable language features
-
-language:dynamics
Allow direct or indirect subclasses of scala.Dynamic
-language:existentials
Existential types (besides wildcard types) can be written and inferred
-language:higherKinds
Allow higher-kinded types
-language:implicitConversions
Allow definition of implicit functions called views
-language:postfixOps
Allow postfix operator notation, such as
1 to 10 toList
(not recommended)-language:reflectiveCalls
Allow reflective access to members of structural types
-language:experimental.macros
Allow macro definition (besides implementation and application)
-
-no-specialization
or--no-specialization
-
Ignore @specialize annotations.
-
-nobootcp
or--no-boot-class-path
-
Do not use the boot classpath for the scala jars.
-
-nowarn
or--no-warnings
-
Generate no warnings.
-
-opt:OPTIMIZATION1,OPTIMIZATION2
-
Enable optimizations
-
-opt:unreachable-code
Eliminate unreachable code, exception handlers guarding no instructions, redundant metadata (debug information, line numbers).
-opt:simplify-jumps
Simplify branching instructions, eliminate unnecessary ones.
-opt:compact-locals
Eliminate empty slots in the sequence of local variables.
-opt:copy-propagation
Eliminate redundant local variables and unused values (including closures). Enables unreachable-code.
-opt:redundant-casts
Eliminate redundant casts using a type propagation analysis.
-opt:box-unbox
Eliminate box-unbox pairs within the same method (also tuples, xRefs, value class instances). Enables unreachable-code.
-opt:nullness-tracking
Track nullness / non-nullness of local variables and apply optimizations.
-opt:closure-invocations
Rewrite closure invocations to the implementation method.
-opt:allow-skip-core-module-init
Allow eliminating unused module loads for core modules of the standard library (e.g., Predef, ClassTag).
-opt:assume-modules-non-null
Assume loading a module never results in null (happens if the module is accessed in its super constructor).
-opt:allow-skip-class-loading
Allow optimizations that can skip or delay class loading.
-opt:inline
Inline method invocations according to -Yopt-inline-heuristics and -opt-inline-from.
-opt:l:none
Disable optimizations. Takes precedence:
-opt:l:none,+box-unbox
/-opt:l:none -opt:box-unbox
don`t enable box-unbox.-opt:l:default
Enable default optimizations: unreachable-code.
-opt:l:method
Enable intra-method optimizations: unreachable-code,simplify-jumps,compact-locals,copy-propagation,redundant-casts,box-unbox,nullness-tracking,closure-invocations,allow-skip-core-module-init,assume-modules-non-null,allow-skip-class-loading.
-opt:l:inline
Enable cross-method optimizations (note: inlining requires -opt-inline-from): l:method,inline.
-
-opt-inline-from PATTERNS1,PATTERNS2
-
Patterns for classfile names from which to allow inlining,
help
for details. -
-opt-warnings:WARNING1,WARNING2
-
Enable optimizer warnings
-
-opt-warnings:none
No optimizer warnings.
-opt-warnings:at-inline-failed-summary
One-line summary if there were @inline method calls that could not be inlined.
-opt-warnings:at-inline-failed
A detailed warning for each @inline method call that could not be inlined.
-opt-warnings:any-inline-failed
A detailed warning for every callsite that was chosen for inlining by the heuristics, but could not be inlined.
-opt-warnings:no-inline-mixed
In mixed compilation, warn at callsites methods defined in java sources (the inlining decision cannot be made without bytecode).
-opt-warnings:no-inline-missing-bytecode
Warn if an inlining decision cannot be made because a the bytecode of a class or member cannot be found on the compilation classpath.
-opt-warnings:no-inline-missing-attribute
Warn if an inlining decision cannot be made because a Scala classfile does not have a ScalaInlineInfo attribute.
-
-optimize
or-optimise
-
Enables optimizations.
-
-print
or--print
-
Print program with Scala-specific features removed.
-
-release RELEASE
or--release RELEASE
-
Compile for a specific version of the Java platform. Supported targets: 6, 7, 8, 9
-
-sourcepath PATH
or--source-path PATH
-
Specify location(s) of source files.
-
-target:TARGET
or--target:TARGET
-
Target platform for object files. ([8],9,10,11,12)
Default:8
-
-target:8
-target:9
-target:10
-target:11
-target:12
-
-toolcp PATH
or--tool-class-path PATH
-
Add to the runner classpath.
-
-unchecked
or--unchecked
-
Enable additional warnings where generated code depends on assumptions.
-
-uniqid
or--unique-id
-
Uniquely tag all identifiers in debugging output.
-
-usejavacp
or--use-java-class-path
-
Utilize the java.class.path in classpath resolution.
-
-usemanifestcp
or--use-manifest-class-path
-
Utilize the manifest in classpath resolution.
-
-verbose
or--verbose
-
Output messages about what the compiler is doing.
-
-version
or--version
-
Print product version and exit.
-
@<file>
-
A text file containing compiler arguments (options and source files)
Advanced Settings
-
-Xcheckinit
-
Wrap field accessors to throw an exception on uninitialized access.
-
-Xdev
-
Indicates user is a developer - issue warnings about anything which seems amiss
-
-Xdisable-assertions
-
Generate no assertions or assumptions.
-
-Xelide-below ARG
-
Calls to @elidable methods are omitted if method priority is lower than argument
Default:-2147483648
-
-Xexperimental
-
Former graveyard for language-forking extensions.
-
-Xfuture
-
Replaced by -Xsource.
-
-Xgenerate-phase-graph FILE
-
Generate the phase graphs (outputs .dot files) to fileX.dot.
-
-Xlint:WARNING1,WARNING2
-
Enable recommended warnings
-
-Xlint:adapted-args
Warn if an argument list is modified to match the receiver.
-Xlint:nullary-unit
Warn when nullary methods return Unit.
-Xlint:inaccessible
Warn about inaccessible types in method signatures.
-Xlint:nullary-override
Warn when non-nullary
def f()
overrides nullarydef f
.-Xlint:infer-any
Warn when a type argument is inferred to be
Any
.-Xlint:missing-interpolator
A string literal appears to be missing an interpolator id.
-Xlint:doc-detached
A Scaladoc comment appears to be detached from its element.
-Xlint:private-shadow
A private field (or class parameter) shadows a superclass field.
-Xlint:type-parameter-shadow
A local type parameter shadows a type already in scope.
-Xlint:poly-implicit-overload
Parameterized overloaded implicit methods are not visible as view bounds.
-Xlint:option-implicit
Option.apply used implicit view.
-Xlint:delayedinit-select
Selecting member of DelayedInit.
-Xlint:package-object-classes
Class or object defined in package object.
-Xlint:stars-align
Pattern sequence wildcard must align with sequence component.
-Xlint:constant
Evaluation of a constant arithmetic expression results in an error.
-Xlint:unused
Enable -Wunused:imports,privates,locals,implicits.
-Xlint:nonlocal-return
A return statement used an exception for flow control.
-Xlint:implicit-not-found
Check @implicitNotFound and @implicitAmbiguous messages.
-Xlint:serial
@SerialVersionUID on traits and non-serializable classes.
-Xlint:valpattern
Enable pattern checks in val definitions.
-Xlint:eta-zero
Warn on eta-expansion (rather than auto-application) of zero-ary method.
-Xlint:eta-sam
Warn on eta-expansion to meet a Java-defined functional interface that is not explicitly annotated with @FunctionalInterface.
-Xlint:deprecation
Enable linted deprecations.
-
-Xmacro-settings OPTION1,OPTION2
-
Custom settings for macros.
-
-Xmain-class PATH
-
Class for manifest’s Main-Class entry (only useful with -d jar)
-
-Xmaxerrs ARG
-
Maximum errors to print
Default:100
-
-Xmaxwarns ARG
-
Maximum warnings to print
Default:100
-
-Xmigration VERSION
-
Warn about constructs whose behavior may have changed since version.
Default:none
-
-Xmixin-force-forwarders:MODE
-
Generate forwarder methods in classes inhering concrete methods from traits. Default:
Default:true
,help
to list choices.true
-
-Xmixin-force-forwarders:true
Always generate mixin forwarders.
-Xmixin-force-forwarders:junit
Generate mixin forwarders for JUnit-annotated methods (JUnit 4 does not support default methods).
-Xmixin-force-forwarders:false
Only generate mixin forwarders required for program correctness.
-
-Xno-forwarders
-
Do not generate static forwarders in mirror classes.
-
-Xno-patmat-analysis
-
Don’t perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.
-
-Xnojline
-
Do not use JLine for editing.
-
-Xplugin PATHS1,PATHS2
-
Load a plugin from each classpath.
-
-Xplugin-disable PLUGIN1,PLUGIN2
-
Disable plugins by name.
-
-Xplugin-list
-
Print a synopsis of loaded plugins.
-
-Xplugin-require PLUGIN1,PLUGIN2
-
Abort if a named plugin is not loaded.
-
-Xpluginsdir PATH
-
Path to search for plugin archives.
Default:
-
-Xprompt
-
Display a prompt after each error (debugging option).
-
-Xreporter CLASSNAME
-
Specify a custom reporter for compiler messages.
Default:scala.tools.nsc.reporters.ConsoleReporter
-
-Xresident
-
Compiler stays resident: read source filenames from standard input.
-
-Xscript OBJECT
-
Treat the source file as a script and wrap it in a main method.
-
-Xsource VERSION
-
Treat compiler input as Scala source for the specified version, see scala/bug#8126.
Default:2.13.0
-
-Xsource-reader CLASSNAME
-
Specify a custom method for reading source files.
-
-Xverify
-
Verify generic signatures in generated bytecode.
-
-Xxml:PROPERTY1,PROPERTY2
-
Configure XML parsing.
-
-Xxml:coalescing
Convert PCData to Text and coalesce sibling nodes
Verbose Settings
-
-Vbrowse ARG
or-Ybrowse ARG
-
Browse the abstract syntax tree after phases
-
-Vclasspath
or-Ylog-classpath
-
Output information about what classpath is being applied.
-
-Vdebug
or-Ydebug
-
Increase the quantity of debugging output.
-
-Vdoc
or-Ydoc-debug
-
Trace scaladoc activity.
-
-Vfree-terms
or-Xlog-free-terms
-
Print a message when reification creates a free term.
-
-Vfree-types
or-Xlog-free-types
-
Print a message when reification resorts to generating a free type.
-
-Vhot-statistics
or-Yhot-statistics
-
Enable
-Vstatistics
to also print hot statistics. -
-Vide
or-Yide-debug
-
Generate, validate and output trees using the interactive compiler.
-
-Vimplicit-conversions
or-Xlog-implicit-conversions
-
Print a message whenever an implicit conversion is inserted.
-
-Vimplicits
or-Xlog-implicits
-
Print dependent missing implicits.
-
-Vimplicits-verbose-tree
-
Display all intermediate implicits in a chain.
-
-Vimplicits-max-refined ARG
-
max chars for printing refined types, abbreviate to
Default:F {...}
0
-
-Vtype-diffs
-
Print found/required error messages as colored diffs.
-
-Vinline PACKAGE/CLASS.METHOD
or-Yopt-log-inline PACKAGE/CLASS.METHOD
-
Print a summary of inliner activity;
_
to print all, prefix match to select. -
-Vissue
or-Yissue-debug
-
Print stack traces when a context issues an error.
-
-Vlog ARG
or-Ylog ARG
-
Log operations during phases
-
-Vmacro
or-Ymacro-debug-verbose
-
Trace macro activities: compilation, generation of synthetics, classloading, expansion, exceptions.
-
-Vmacro-lite
or-Ymacro-debug-lite
-
Trace macro activities with less output.
-
-Vopt PACKAGE/CLASS.METHOD
or-Yopt-trace PACKAGE/CLASS.METHOD
-
Trace the optimizer progress for methods;
_
to print all, prefix match to select. -
-Vpatmat
or-Ypatmat-debug
-
Trace pattern matching translation.
-
-Vphases
or-Xshow-phases
-
Print a synopsis of compiler phases.
-
-Vpos
or-Ypos-debug
-
Trace position validation.
-
-Vprint ARG
or-Xprint ARG
-
Print out program after phases
-
-Vprint-args FILE
or-Xprint-args FILE
-
Print all compiler arguments to the specified location. Use - to echo to the reporter.
Default:-
-
-Vprint-pos
or-Xprint-pos
-
Print tree positions, as offsets.
-
-Vprint-types
or-Xprint-types
-
Print tree types (debugging option).
-
-Vquasiquote
or-Yquasiquote-debug
-
Trace quasiquotations.
-
-Vreflective-calls
or-Xlog-reflective-calls
-
Print a message when a reflective method call is generated
-
-Vreify
or-Yreify-debug
-
Trace reification.
-
-Vshow ARG
or-Yshow ARG
-
(Requires -Xshow-class or -Xshow-object) Show after phases
-
-Vshow-class CLASS
or-Xshow-class CLASS
-
Show internal representation of class.
-
-Vshow-member-pos OUTPUT STYLE
or-Yshow-member-pos OUTPUT STYLE
-
Show start and end positions of members (implies -Yrangepos)
-
-Vshow-object OBJECT
or-Xshow-object OBJECT
-
Show internal representation of object.
-
-Vshow-symkinds
or-Yshow-symkinds
-
Print abbreviated symbol kinds next to symbol names.
-
-Vshow-symowners
or-Yshow-symowners
-
Print owner identifiers next to symbol names.
-
-Vstatistics ARG
or-Ystatistics ARG
-
Print compiler statistics for specific phases phases (default: parser,typer,patmat,erasure,cleanup,jvm)
Default:parser,typer,patmat,erasure,cleanup,jvm
-
-Vsymbols
or-Yshow-syms
-
Print the AST symbol hierarchy after each phase.
-
-Vtyper
or-Ytyper-debug
-
Trace type assignments.
Private Settings
-
-Ybackend-parallelism ARG
-
maximum worker threads for backend
Default:1
Min:1
Max:16
-
-Ybackend-worker-queue ARG
-
backend threads worker queue size
Default:0
Min:0
Max:1000
-
-Ybreak-cycles
-
Attempt to break cycles encountered during typing
-
-Ycache-macro-class-loader:POLICY
-
Policy for caching class loaders for macros that are dynamically loaded. Default:
Default:none
,help
to list choices.none
-
-Ycache-macro-class-loader:none
Don’t cache class loader
-Ycache-macro-class-loader:last-modified
Cache class loader, using file last-modified time to invalidate
-Ycache-macro-class-loader:always
Cache class loader with no invalidation
-
-Ycache-plugin-class-loader:POLICY
-
Policy for caching class loaders for compiler plugins that are dynamically loaded. Default:
Default:none
,help
to list choices.none
-
-Ycache-plugin-class-loader:none
Don’t cache class loader
-Ycache-plugin-class-loader:last-modified
Cache class loader, using file last-modified time to invalidate
-Ycache-plugin-class-loader:always
Cache class loader with no invalidation
-
-Ycheck ARG
-
Check the tree at the end of phases
-
-Ycompact-trees
-
Use compact tree printer when displaying trees.
-
-Ydelambdafy:STRATEGY
-
Strategy used for translating lambdas into JVM code. (inline,[method])
Default:method
-
-Ydelambdafy:inline
-Ydelambdafy:method
-
-Ydump-classes DIR
-
Dump the generated bytecode to .class files (useful for reflective compilation that utilizes in-memory classloaders).
-
-Ygen-asmp DIR
-
Generate a parallel output directory of .asmp files (ie ASM Textifier output).
-
-Yimports IMPORT1,IMPORT2
-
Custom root imports, default is
java.lang,scala,scala.Predef
. -
-Yjar-compression-level ARG
-
compression level to use when writing jar files
Default:-1
Min:-1
Max:9
-
-Ymacro-annotations
-
Enable support for macro annotations, formerly in macro paradise.
-
-Ymacro-classpath PATH
-
The classpath used to reflectively load macro implementations, default is the compilation classpath.
-
-Ymacro-expand:POLICY
-
Control expansion of macros, useful for scaladoc and presentation compiler. ([normal],none,discard)
Default:normal
-
-Ymacro-expand:normal
-Ymacro-expand:none
-Ymacro-expand:discard
-
-Ymacro-global-fresh-names
-
Should fresh names in macros be unique across all compilation units
-
-Yno-completion
-
Disable tab-completion in the REPL.
-
-Yno-flat-classpath-cache
or-YdisableFlatCpCaching
-
Do not cache flat classpath representation of classpath elements from jars across compiler instances.
-
-Yno-generic-signatures
-
Suppress generation of generic signatures for Java.
-
-Yno-imports
-
Compile without importing scala., java.lang., or Predef.
-
-Yno-predef
-
Compile without importing Predef.
-
-Yopt-inline-heuristics:STRATEGY
-
Set the heuristics for inlining decisions. (at-inline-annotated,everything,[default])
Default:default
-
-Yopt-inline-heuristics:at-inline-annotated
-Yopt-inline-heuristics:everything
-Yopt-inline-heuristics:default
-
-Ypatmat-exhaust-depth ARG
-
off
Default:20
Min:10
Max:2147483647
-
-Yprint-trees:STYLE
-
How to print trees when -Vprint is enabled. ([text],compact,format,text+format)
Default:text
-
-Yprint-trees:text
-Yprint-trees:compact
-Yprint-trees:format
-Yprint-trees:text+format
-
-Yprofile-destination FILE
-
Profiling output - specify a file or
-
for console. -
-Yprofile-enabled
-
Enable profiling.
-
-Yprofile-external-tool ARG
-
Enable profiling for a phase using an external tool hook. Generally only useful for a single phase phases (default: typer)
Default:typer
-
-Yprofile-run-gc ARG
-
Run a GC between phases - this allows heap size to be accurate at the expense of more time. Specify a list of phases, or all phases (default: _)
Default:_
-
-Yprofile-trace FILE
-
Capture trace of compilation in Chrome Trace format
Default:profile.trace
-
-Yrangepos
-
Use range positions for syntax trees.
-
-Yrecursion ARG
-
Set recursion depth used when locking symbols.
Default:0
Min:0
Max:2147483647
-
-Yreify-copypaste
-
Dump the reified trees in copypasteable representation.
-
-Yrepl-class-based
-
Use classes to wrap REPL snippets instead of objects
-
-Yrepl-outdir PATH
-
Write repl-generated classfiles to given output directory (use “” to generate a temporary dir)
-
-Yresolve-term-conflict:STRATEGY
-
Resolve term conflicts. (package,object,[error])
Default:error
-
-Yresolve-term-conflict:package
-Yresolve-term-conflict:object
-Yresolve-term-conflict:error
-
-Yscriptrunner CLASSNAME
-
Specify a scala.tools.nsc.ScriptRunner (default, resident, shutdown, or a class name).
Default:default
-
-Yskip ARG
-
Skip phases
-
-Ystop-after ARG
or-stop ARG
-
Stop after phases
-
-Ystop-before ARG
-
Stop before phases
-
-Yvalidate-pos ARG
-
Validate positions after the given phases (implies -Yrangepos) phases
Warning Settings
-
-Wdead-code
or-Ywarn-dead-code
-
Warn when dead code is identified.
-
-Wextra-implicit
or-Ywarn-extra-implicit
-
Warn when more than one implicit parameter section is defined.
-
-Wmacros:MODE
or-Ywarn-macros:MODE
-
Enable lint warnings on macro expansions. Default:
Default:before
,help
to list choices.before
-
-Wmacros:none
Do not inspect expansions or their original trees when generating unused symbol warnings.
-Wmacros:before
Only inspect unexpanded user-written code for unused symbols.
-Wmacros:after
Only inspect expanded trees when generating unused symbol warnings.
-Wmacros:both
Inspect both user-written code and expanded trees when generating unused symbol warnings.
-
-Wnumeric-widen
or-Ywarn-numeric-widen
-
Warn when numerics are widened.
-
-Woctal-literal
or-Ywarn-octal-literal
-
Warn on obsolete octal syntax.
-
-Wself-implicit
or-Ywarn-self-implicit
-
Warn when an implicit resolves to an enclosing self-definition.
-
-Wunused:WARNING1,WARNING2
or-Ywarn-unused:WARNING1,WARNING2
-
Enable or disable specific
unused
warnings -
-Wunused:imports
Warn if an import selector is not referenced.
-Wunused:patvars
Warn if a variable bound in a pattern is unused.
-Wunused:privates
Warn if a private member is unused.
-Wunused:locals
Warn if a local definition is unused.
-Wunused:explicits
Warn if an explicit parameter is unused.
-Wunused:implicits
Warn if an implicit parameter is unused.
-Wunused:params
Enable -Wunused:explicits,implicits.
-Wunused:linted
-Xlint:unused.
-
-Wvalue-discard
or-Ywarn-value-discard
-
Warn when non-Unit expression results are unused.
-
-Xlint:WARNING1,WARNING2
-
Enable recommended warnings
-
-Xlint:adapted-args
Warn if an argument list is modified to match the receiver.
-Xlint:nullary-unit
Warn when nullary methods return Unit.
-Xlint:inaccessible
Warn about inaccessible types in method signatures.
-Xlint:nullary-override
Warn when non-nullary
def f()
overrides nullarydef f
.-Xlint:infer-any
Warn when a type argument is inferred to be
Any
.-Xlint:missing-interpolator
A string literal appears to be missing an interpolator id.
-Xlint:doc-detached
A Scaladoc comment appears to be detached from its element.
-Xlint:private-shadow
A private field (or class parameter) shadows a superclass field.
-Xlint:type-parameter-shadow
A local type parameter shadows a type already in scope.
-Xlint:poly-implicit-overload
Parameterized overloaded implicit methods are not visible as view bounds.
-Xlint:option-implicit
Option.apply used implicit view.
-Xlint:delayedinit-select
Selecting member of DelayedInit.
-Xlint:package-object-classes
Class or object defined in package object.
-Xlint:stars-align
Pattern sequence wildcard must align with sequence component.
-Xlint:constant
Evaluation of a constant arithmetic expression results in an error.
-Xlint:unused
Enable -Wunused:imports,privates,locals,implicits.
-Xlint:nonlocal-return
A return statement used an exception for flow control.
-Xlint:implicit-not-found
Check @implicitNotFound and @implicitAmbiguous messages.
-Xlint:serial
@SerialVersionUID on traits and non-serializable classes.
-Xlint:valpattern
Enable pattern checks in val definitions.
-Xlint:eta-zero
Warn on eta-expansion (rather than auto-application) of zero-ary method.
-Xlint:eta-sam
Warn on eta-expansion to meet a Java-defined functional interface that is not explicitly annotated with @FunctionalInterface.
-Xlint:deprecation
Enable linted deprecations.
IDE-specific Settings
-
-Ypresentation-any-thread
-
Allow use of the presentation compiler from any thread
-
-Ypresentation-debug
-
Enable debugging output for the presentation compiler.
-
-Ypresentation-delay ARG
-
Wait number of ms after typing before starting typechecking
Default:0
Min:0
Max:999
-
-Ypresentation-log FILE
-
Log presentation compiler events into file
-
-Ypresentation-replay FILE
-
Replay presentation compiler events from file
-
-Ypresentation-strict
-
Do not report type errors in sources with syntax errors.
-
-Ypresentation-verbose
-
Print information about presentation compiler tasks.
Targeting a version of the JVM
Applications or libraries targeting the JVM may wish to specify a target version.
The -release
option specifies the target version, such as “8” or “18”.
Like the option for javac
, it allows building against an earlier version of the JDK. It will compile against the API for that version and also output class files for that version.
The deprecated option -target
does not compile against the desired API, but only specifies a target class file format.
Additional resources
Compilation Phases
- parser
- parse source into ASTs, perform simple desugaring
- namer
- resolve names, attach symbols to named trees
- packageobjects
- load package objects
- typer
- the meat and potatoes: type the trees
- superaccessors
- add super accessors in traits and nested classes
- extmethods
- add extension methods for inline classes
- pickler
- serialize symbol tables
- refchecks
- reference/override checking, translate nested objects
- patmat
- translate match expressions
- uncurry
- uncurry, translate function values to anonymous classes
- fields
- synthesize accessors and fields, add bitmaps for lazy vals
- tailcalls
- replace tail calls by jumps
- specialize
- @specialized-driven class and method specialization
- explicitouter
- this refs to outer pointers
- erasure
- erase types, add interfaces for traits
- posterasure
- clean up erased inline classes
- lambdalift
- move nested functions to top level
- constructors
- move field definitions into constructors
- flatten
- eliminate inner classes
- mixin
- mixin composition
- cleanup
- platform-specific cleanups, generate reflective calls
- delambdafy
- remove lambdas
- jvm
- generate JVM bytecode
- terminal
- the last phase during a compilation run