Scala 3 遷移指南

編譯器選項查詢表

語言

此表格列出 Scala 2.13 編譯器選項及其在 Scala 3 中的等效選項。有些選項具有跨版本支援,例如 -Vprint。其他選項有近似的等效選項,但名稱不同。許多 Scala 2 選項在 Scala 3 中沒有等效選項,例如用於除錯 Scala 2 巨集的選項。

編譯器選項顯示為說明輸出 scalac -helpscalac -X 等所顯示的內容。這裡顯示了一些別名,但大多數較舊的別名,例如 -Xprint 表示 -Vprint,或 -Ytyper-debug 表示 -Vtyper,都以最新的名稱列出。

選項群組 -V-W 在 Scala 2.13 中引入,用於要求額外診斷輸出的「詳細」選項和要求額外檢查(可能表示程式碼錯誤,也可能不表示錯誤)的「警告」。-Werror 將警告提升為錯誤,而 -Wconf 允許精確控制警告,方法是忽略警告或將其視為錯誤。遷移到 Scala 3 時,-Wconf 的組態字串可能需要調整,因為組態語法和它比對的錯誤訊息不同。

狀態 意義
Scala 3 中提供。
<new-name> 已重新命名為 <new-name>
尚未提供,但可能在稍後新增。

目前的比較基於 Scala 2.13.10 和 3.3.0。

標準設定

2.13.x 3.3.x
-Dproperty=value
-J<flag>
-P:<plugin>:<opt>
-V
-W
-X
-Y
-bootclasspath
-classpath
-d
-dependencyfile
-deprecation
-encoding
-explaintypes -explain-types
-extdirs
-feature
-g
-help
-javabootclasspath
-javaextdirs
-language
-no-specialization
-nobootcp
-nowarn
-opt
-opt-inline-from
-opt-warnings
-optimize
-print
-release
-rootdir
-sourcepath
-target -Xtarget
-toolcp
-unchecked
-uniqid
-usejavacp
-usemanifestc
-verbose
-version

詳細設定

2.13.x 3.3.x
-Vbrowse:<phases>
-Vclasspath -Ylog-classpath
-Vdebug -Ydebug
-Vdebug-tasty
-Vdebug-type-error
-Vdoc
-Vfree-terms
-Vfree-types
-Vhot-statistics
-Vide
-Vimplicit-conversions
-Vimplicits
-Vimplicits-max-refined
-Vimplicits-verbose-tree
-Vinline <package/Class.method>
-Vlog:<phases> -Ylog:<phases>
-Vmacro
-Vmacro-lite
-Vopt <package/Class.method>
-Vpatmat
-Vphases
-Vpos
-Vprint:<phases>
-Vprint-args <file>
-Vprint-pos -Yprint-pos
-Vprint-types -Xprint-types
-Vquasiquote
-Vreflective-calls
-Vreify
-Vshow:<phases>
-Vshow-class <class>
-Vshow-member-pos <output style>
-Vshow-object <object>
-Vshow-symkinds
-Vshow-symowners
-Vstatistics <phases>
-Vsymbols
-Vtype-diffs
-Vtyper

警告設定

2.13.x 3.3.x
-Wconf
-Wdead-code
-Werror
-Wextra-implicit
-Wmacros:<mode>
-Wnonunit-if
-Wnonunit-statement
-Wnumeric-widen
-Woctal-literal
-Wopt
-Wperformance
-Wself-implicit
-Wunused:<warnings>
-Wvalue-discard

進階設定

2.13.x 3.3.x
-Xasync
-Xcheckinit -Ysafe-init
-Xdev
-Xdisable-assertions
-Xelide-below
-Xexperimental
-Xfuture
-Xgenerate-phase-graph
-Xjline
-Xlint:deprecation -deprecation
-Xlint:<warnings>
-Xmacro-settings
-Xmain-class
-Xmaxerrs
-Xmaxwarns
-Xmigration
-Xmixin-force-forwarders
-Xno-forwarders
-Xno-patmat-analysis
-Xnon-strict-patmat-analysis
-Xnojline
-Xplugin
-Xplugin-disable
-Xplugin-list
-Xplugin-require
-Xpluginsdir
-Xprompt
-Xreporter
-Xresident
-Xscript
-Xsource -source
-Xsource-reader
-Xverify -Xverify-signatures
-Xxml

私人設定

2.13.x 3.0.x
-Ybackend-parallelism
-Ybackend-worker-queue
-Ybreak-cycles
-Ycache-macro-class-loader
-Ycache-plugin-class-loader
-Ycheck
-Ycompact-trees
-Ydelambdafy
-Ydump-classes
-Ygen-asmp
-Yimports
-Yissue-debug
-Yjar-compression-level
-YjarFactory
-Ymacro-annotations
-Ymacro-classpath
-Ymacro-expand
-Ymacro-global-fresh-names
-Yno-completion
-Yno-flat-classpath-cache
-Yno-generic-signatures
-Yno-imports
-Yno-predef
-Yopt-inline-heuristics
-Ypatmat-exhaust-depth
-Ypresentation-any-thread
-Ypresentation-debug
-Ypresentation-delay
-Ypresentation-locate-source-file
-Ypresentation-log
-Ypresentation-replay
-Ypresentation-strict
-Ypresentation-verbose
-Yprint-trees
-Yprofile-destination
-Yprofile-enabled
-Yprofile-external-tool
-Yprofile-run-gc
-Yprofile-trace
-Yrangepos
-Yrecursion
-Yreify-copypaste
-Yrepl-class-based
-Yrepl-outdir
-Yrepl-use-magic-imports
-Yresolve-term-conflict
-Yscala3-implicit-resolution
-Yscriptrunner
-Yskip
-Ystop-after
-Ystop-before
-Ytasty-no-annotations
-Ytasty-reader
-Ytrack-dependencies
-Yvalidate-pos

編譯器外掛程式

一些有用的 Scala 2.13 編譯器外掛程式現在已發布到編譯器中。你可以使用一些新的原生選項來啟用和設定它們。

Scala.js

2.13.x 3.0.x
-Xplugin:scalajs-compiler_<version>.jar -scalajs
-P:scalajs:genStaticForwardersForNonTopLevelObjects -scalajs-genStaticForwardersForNonTopLevelObjects
-P:scalajs:mapSourceURI -scalajs-mapSourceURI

SemanticDB

2.13.x 3.0.x
-Xplugin:semanticdb-scalac_<version>.jar -Xsemanticdb
-P:semanticdb:targetroot:<path> -semanticdb-target:<path>

Kind-Projector

2.13.x 3.0.x
-Xplugin:kind-projector_<version>.jar -Ykind-projector

此頁面的貢獻者