Skip to content

Commit cd60e8c

Browse files
authored
Merge pull request #423 from scala/backport-lts-3.3-23215
Backport "chore: filter allowed source versions by import and by settings" to 3.3 LTS
2 parents 53bb795 + 2b859ac commit cd60e8c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import core.Decorators.*
66
import util.Property
77

88
enum SourceVersion:
9-
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.
9+
case `3.0-migration`, `3.0`
10+
case `3.1-migration`, `3.1`
1011
case `3.2-migration`, `3.2`
1112
case `3.3-migration`, `3.3`
1213
case `future-migration`, `future`
@@ -21,10 +22,17 @@ enum SourceVersion:
2122
def isAtMost(v: SourceVersion) = stable.ordinal <= v.ordinal
2223

2324
object SourceVersion extends Property.Key[SourceVersion]:
25+
2426
def defaultSourceVersion = `3.3`
2527

28+
/* Illegal source versions that may not appear in the settings `-source:<...>` */
29+
val illegalInSettings = List(`3.1-migration`, `never`)
30+
31+
/* Illegal source versions that may not appear as an import `import scala.language.<...>` */
32+
val illegalInImports = List(`3.1-migration`, `never`)
33+
2634
/** language versions that may appear in a language import, are deprecated, but not removed from the standard library. */
27-
val illegalSourceVersionNames = List("3.1-migration").map(_.toTermName)
35+
val illegalSourceVersionNames = "3.1-migration" :: illegalInImports.map(_.toString.toTermName)
2836

2937
/** language versions that the compiler recognises. */
3038
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
@@ -199,4 +199,11 @@ class ScalaSettingsTests:
199199
)
200200
assertEquals(result, Right(reporting.Action.Error))
201201

202+
@Test def `illegal source versions are not accepted when parsing the settings`: Unit =
203+
for source <- SourceVersion.illegalInSettings do
204+
val settings = ScalaSettings
205+
val result = settings.processArguments(List("-source", source.toString()), true)
206+
assertEquals(0, result.warnings.length)
207+
assertEquals(1, result.errors.length)
208+
202209
end ScalaSettingsTests

0 commit comments

Comments
 (0)