Skip to content

Commit 825598c

Browse files
committed
Add help to choices
1 parent c460526 commit 825598c

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SourceVersion.*
1111
import reporting.Message
1212
import NameKinds.QualifiedName
1313
import Annotations.ExperimentalAnnotation
14+
import Settings.Setting.ChoiceWithHelp
1415

1516
object Feature:
1617

@@ -35,14 +36,31 @@ object Feature:
3536
val into = experimental("into")
3637

3738
val values = List(
38-
nme.help,
39-
nme.noAutoTupling, nme.dynamics, nme.unsafeNulls, nme.postfixOps, nme.strictEquality,
40-
nme.implicitConversions, nme.adhocExtensions,
41-
namedTypeArguments, genericNumberLiterals, scala2macros,
42-
dependent, erasedDefinitions, symbolLiterals, fewerBraces, saferExceptions,
43-
clauseInterleaving, pureFunctions, captureChecking, into
39+
(nme.help, "Display all available features"),
40+
(nme.noAutoTupling, "Disable automatic tupling"),
41+
(nme.dynamics, "Allow direct or indirect subclasses of scala.Dynamic"),
42+
(nme.unsafeNulls, "Enable unsafe nulls for explicit nulls"),
43+
(nme.postfixOps, "Allow postfix operator notation"),
44+
(nme.strictEquality, "Enable strict equality (=== and !==)"),
45+
(nme.implicitConversions, "Allow implicit conversions without warnings"),
46+
(nme.adhocExtensions, "Allow ad-hoc extension methods"),
47+
(namedTypeArguments, "Allow named type arguments"),
48+
(genericNumberLiterals, "Allow generic number literals"),
49+
(scala2macros, "Allow Scala 2 macros"),
50+
(dependent, "Allow dependent method types"),
51+
(erasedDefinitions, "Allow erased definitions"),
52+
(symbolLiterals, "Allow symbol literals"),
53+
(fewerBraces, "Allow fewer braces"),
54+
(saferExceptions, "Enable safer exceptions"),
55+
(clauseInterleaving, "Enable clause interleaving"),
56+
(pureFunctions, "Enable pure functions"),
57+
(captureChecking, "Enable experimental capture checking"),
58+
(into, "Allow into clauses in pattern matches")
4459
)
4560

61+
private def enabledLanguageFeaturesBySetting(using Context): List[String] =
62+
ctx.settings.language.value.asInstanceOf
63+
4664
/** Is `feature` enabled by by a command-line setting? The enabling setting is
4765
*
4866
* -language:<prefix>feature
@@ -51,7 +69,7 @@ object Feature:
5169
* but subtracting the prefix `scala.language.` at the front.
5270
*/
5371
def enabledBySetting(feature: TermName)(using Context): Boolean =
54-
ctx.base.settings.language.value.contains(feature.toString)
72+
enabledLanguageFeaturesBySetting.contains(feature.toString)
5573

5674
/** Is `feature` enabled by by an import? This is the case if the feature
5775
* is imported by a named import
@@ -172,7 +190,7 @@ object Feature:
172190

173191
/** Check that experimental compiler options are only set for snapshot or nightly compiler versions. */
174192
def checkExperimentalSettings(using Context): Unit =
175-
for setting <- ctx.settings.language.value
193+
for setting <- enabledLanguageFeaturesBySetting
176194
if setting.startsWith("experimental.") && setting != "experimental.macros"
177195
do checkExperimentalFeature(s"feature $setting", NoSourcePosition)
178196

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ trait CommonScalaSettings:
114114
val explainTypes: Setting[Boolean] = BooleanSetting(RootSetting, "explain-types", "Explain type errors in more detail (deprecated, use -explain instead).", aliases = List("--explain-types", "-explaintypes"))
115115
val explainCyclic: Setting[Boolean] = BooleanSetting(RootSetting, "explain-cyclic", "Explain cyclic reference errors in more detail.", aliases = List("--explain-cyclic"))
116116
val unchecked: Setting[Boolean] = BooleanSetting(RootSetting, "unchecked", "Enable additional warnings where generated code depends on assumptions.", initialValue = true, aliases = List("--unchecked"))
117-
val language: Setting[List[String]] = MultiChoiceSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices = ScalaSettingsProperties.supportedLanguageFeatures, aliases = List("--language"))
117+
val language: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices = ScalaSettingsProperties.supportedLanguageFeatures, default = Nil, aliases = List("--language"))
118118
val experimental: Setting[Boolean] = BooleanSetting(RootSetting, "experimental", "Annotate all top-level definitions with @experimental. This enables the use of experimental features anywhere in the project.")
119119

120120
/* Coverage settings */
@@ -448,3 +448,4 @@ private sealed trait YSettings:
448448
val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true)
449449
val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.")
450450
end YSettings
451+

compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.dotc
22
package config
33

4+
import Settings.Setting.ChoiceWithHelp
45
import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap
56
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
67
import scala.language.unsafeNulls
@@ -26,8 +27,8 @@ object ScalaSettingsProperties:
2627
def supportedSourceVersions: List[String] =
2728
SourceVersion.values.toList.map(_.toString)
2829

29-
def supportedLanguageFeatures: List[String] =
30-
Feature.values.toList.map(_.toString)
30+
def supportedLanguageFeatures: List[ChoiceWithHelp[String]] =
31+
Feature.values.map((n, d) => ChoiceWithHelp(n.toString, d))
3132

3233
def defaultClasspath: String = sys.env.getOrElse("CLASSPATH", ".")
3334

0 commit comments

Comments
 (0)