Skip to content

Commit ab33bb1

Browse files
hamzaremmaltgodzik
authored andcommitted
chore: filter allowed source versions by import and by settings
1 parent 3e4b8fd commit ab33bb1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ enum SourceVersion:
2121
def isAtMost(v: SourceVersion) = stable.ordinal <= v.ordinal
2222

2323
object SourceVersion extends Property.Key[SourceVersion]:
24+
2425
def defaultSourceVersion = `3.3`
2526

27+
/* Illegal source versions that may not appear in the settings `-source:<...>` */
28+
val illegalInSettings = List(`never`)
29+
30+
/* Illegal source versions that may not appear as an import `import scala.language.<...>` */
31+
val illegalInImports = List(`never`)
32+
2633
/** 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)
34+
val illegalSourceVersionNames = "3.1-migration" :: illegalInImports.map(_.toString.toTermName)
2835

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