Skip to content

Commit 473f8ce

Browse files
committed
chore: filter allowed source versions by import and by settings
1 parent d36e423 commit 473f8ce

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ object ScalaSettingsProperties:
2424
ScalaRelease.values.toList.map(_.show)
2525

2626
def supportedSourceVersions: List[String] =
27-
(SourceVersion.values.toList.diff(SourceVersion.illegalSourceVersionNames)).toList.map(_.toString)
27+
SourceVersion.values.diff(SourceVersion.illegalInSettings)
28+
.map(_.toString).toList
2829

2930
def supportedLanguageFeatures: List[ChoiceWithHelp[String]] =
3031
Feature.values.map((n, d) => ChoiceWithHelp(n.toString, d))

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ enum SourceVersion:
4040
def enablesBetterFors(using Context) = isAtLeast(`3.7`) && isPreviewEnabled
4141

4242
object SourceVersion extends Property.Key[SourceVersion]:
43-
def defaultSourceVersion = `3.7`
43+
44+
/* The default source version used by the built compiler */
45+
val defaultSourceVersion = `3.7`
46+
47+
/* Illegal source versions that may not appear in the settings `-source:<...>` */
48+
val illegalInSettings = List(`never`)
49+
50+
/* Illegal source versions that may not appear as an import `import scala.language.<...>` */
51+
val illegalInImports = List(`never`)
4452

4553
/** language versions that may appear in a language import, are deprecated, but not removed from the standard library. */
46-
val illegalSourceVersionNames = List("3.1-migration", "never").map(_.toTermName)
54+
val illegalSourceVersionNames = illegalInImports.map(_.toString.toTermName)
4755

4856
/** language versions that the compiler recognises. */
4957
val validSourceVersionNames = values.toList.map(_.toString.toTermName)

compiler/test/dotty/tools/dotc/config/ScalaSettingsTests.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,11 @@ class ScalaSettingsTests:
299299
)
300300
assertEquals(result, Right(reporting.Action.Error))
301301

302+
@Test def `illegal source versions are not accepted when parsing the settings`: Unit =
303+
for source <- SourceVersion.illegalInSettings do
304+
val settings = ScalaSettings
305+
val result = settings.processArguments(List("-source", source.toString()), true)
306+
assertEquals(0, result.warnings.length)
307+
assertEquals(1, result.errors.length)
308+
302309
end ScalaSettingsTests

0 commit comments

Comments
 (0)