Skip to content

Backport "chore: filter allowed source versions by import and by settings" to 3.7.1 #23231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: filter allowed source versions by import and by settings
[Cherry-picked 473f8ce]
  • Loading branch information
hamzaremmal authored and WojciechMazur committed May 21, 2025
commit d8c8f29fd25721f2b668b59d23dd4950b536a2b7
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ object ScalaSettingsProperties:
ScalaRelease.values.toList.map(_.show)

def supportedSourceVersions: List[String] =
(SourceVersion.values.toList.diff(SourceVersion.illegalSourceVersionNames)).toList.map(_.toString)
SourceVersion.values.diff(SourceVersion.illegalInSettings)
.map(_.toString).toList

def supportedLanguageFeatures: List[ChoiceWithHelp[String]] =
Feature.values.map((n, d) => ChoiceWithHelp(n.toString, d))
Expand Down
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/config/SourceVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ enum SourceVersion:
def enablesBetterFors(using Context) = isAtLeast(`3.7`) && isPreviewEnabled

object SourceVersion extends Property.Key[SourceVersion]:
def defaultSourceVersion = `3.7`

/* The default source version used by the built compiler */
val defaultSourceVersion = `3.7`

/* Illegal source versions that may not appear in the settings `-source:<...>` */
val illegalInSettings = List(`never`)

/* Illegal source versions that may not appear as an import `import scala.language.<...>` */
val illegalInImports = List(`never`)

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

/** language versions that the compiler recognises. */
val validSourceVersionNames = values.toList.map(_.toString.toTermName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,11 @@ class ScalaSettingsTests:
)
assertEquals(result, Right(reporting.Action.Error))

@Test def `illegal source versions are not accepted when parsing the settings`: Unit =
for source <- SourceVersion.illegalInSettings do
val settings = ScalaSettings
val result = settings.processArguments(List("-source", source.toString()), true)
assertEquals(0, result.warnings.length)
assertEquals(1, result.errors.length)

end ScalaSettingsTests