Skip to content

Commit 9b110ac

Browse files
Backport "chore: filter allowed source versions by import and by settings" to 3.7.1 (#23231)
Backports #23215 to the 3.7.1-RC2. PR submitted by the release tooling.
2 parents de0e016 + 05d2d32 commit 9b110ac

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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

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

2727
def supportedSourceVersions: List[String] =
28-
(SourceVersion.values.toList.diff(SourceVersion.illegalSourceVersionNames)).toList.map(_.toString)
28+
SourceVersion.values.diff(SourceVersion.illegalInSettings)
29+
.map(_.toString).toList
2930

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

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import Feature.isPreviewEnabled
88
import util.Property
99

1010
enum SourceVersion:
11-
case `3.0-migration`, `3.0`, `3.1` // Note: do not add `3.1-migration` here, 3.1 is the same language as 3.0.
11+
case `3.0-migration`, `3.0`
12+
case `3.1-migration`, `3.1`
1213
case `3.2-migration`, `3.2`
1314
case `3.3-migration`, `3.3`
1415
case `3.4-migration`, `3.4`
@@ -40,10 +41,18 @@ enum SourceVersion:
4041
def enablesBetterFors(using Context) = isAtLeast(`3.7`) && isPreviewEnabled
4142

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

4554
/** 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)
55+
val illegalSourceVersionNames = illegalInImports.map(_.toString.toTermName)
4756

4857
/** language versions that the compiler recognises. */
4958
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)