Skip to content

Commit a54d521

Browse files
bishaboshagriggt
andcommitted
introduce infrastructure for 3.2 language features
Co-authored-by: Tom Grigg <[email protected]>
1 parent ac1928a commit a54d521

File tree

8 files changed

+31
-10
lines changed

8 files changed

+31
-10
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ object Feature:
8888
/** If current source migrates to `version`, issue given warning message
8989
* and return `true`, otherwise return `false`.
9090
*/
91-
def warnOnMigration(msg: Message, pos: SrcPos,
92-
version: SourceVersion)(using Context): Boolean =
91+
def warnOnMigration(msg: Message, pos: SrcPos, version: SourceVersion)(using Context): Boolean =
9392
if sourceVersion.isMigrating && sourceVersion.stable == version
9493
|| (version == `3.0` || version == `3.1` || version == `3.2`) && migrateTo3
9594
then

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import scala.language.unsafeNulls
55

66
import dotty.tools.dotc.config.PathResolver.Defaults
77
import dotty.tools.dotc.config.Settings.{Setting, SettingGroup}
8+
import dotty.tools.dotc.config.SourceVersion
89
import dotty.tools.dotc.core.Contexts._
910
import dotty.tools.dotc.rewrites.Rewrites
1011
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory}
@@ -31,6 +32,9 @@ object ScalaSettings:
3132
def supportedScalaReleaseVersions: List[String] =
3233
ScalaRelease.values.toList.map(_.show)
3334

35+
def supportedSourceVersions: List[String] =
36+
SourceVersion.values.toList.map(_.toString)
37+
3438
def defaultClasspath: String = sys.env.getOrElse("CLASSPATH", ".")
3539

3640
def defaultPageWidth: Int = {
@@ -51,7 +55,7 @@ trait AllScalaSettings extends CommonScalaSettings, PluginSettings, VerboseSetti
5155
/* Path related settings */
5256
val semanticdbTarget: Setting[String] = PathSetting("-semanticdb-target", "Specify an alternative output directory for SemanticDB files.", "")
5357

54-
val source: Setting[String] = ChoiceSetting("-source", "source version", "source version", List("3.0", "3.1", "future", "3.0-migration", "future-migration"), "3.0", aliases = List("--source"))
58+
val source: Setting[String] = ChoiceSetting("-source", "source version", "source version", ScalaSettings.supportedSourceVersions, SourceVersion.defaultSourceVersion.toString, aliases = List("--source"))
5559
val uniqid: Setting[Boolean] = BooleanSetting("-uniqid", "Uniquely tag all identifiers in debugging output.", aliases = List("--unique-id"))
5660
val rewrite: Setting[Option[Rewrites]] = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with a `...-migration` source version, rewrites sources to migrate to new version.", aliases = List("--rewrite"))
5761
val fromTasty: Setting[Boolean] = BooleanSetting("-from-tasty", "Compile classes from tasty files. The arguments are .tasty or .jar files.", aliases = List("--from-tasty"))

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import core.Decorators.*
66
import util.Property
77

88
enum SourceVersion:
9-
case `3.0-migration`, `3.0`, `3.1`, `3.2`, `future-migration`, `future`
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.
10+
case `3.2-migration`, `3.2`
11+
case `future-migration`, `future`
1012

1113
val isMigrating: Boolean = toString.endsWith("-migration")
1214

@@ -16,6 +18,7 @@ enum SourceVersion:
1618
def isAtLeast(v: SourceVersion) = stable.ordinal >= v.ordinal
1719

1820
object SourceVersion extends Property.Key[SourceVersion]:
21+
def defaultSourceVersion = `3.0`
1922

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

compiler/src/dotty/tools/dotc/report.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ object report:
6767
error(ex.toMessage, pos, sticky = true)
6868
if ctx.settings.YdebugTypeError.value then ex.printStackTrace()
6969

70-
def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition,
71-
from: SourceVersion)(using Context): Unit =
70+
def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition, from: SourceVersion)(using Context): Unit =
7271
if sourceVersion.isAtLeast(from) then
7372
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos)
7473
else error(msg, pos)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CompilationTests {
3838
compileFilesInDir("tests/pos-special/spec-t5545", defaultOptions),
3939
compileFilesInDir("tests/pos-special/strawman-collections", allowDeepSubtypes),
4040
compileFilesInDir("tests/pos-special/isInstanceOf", allowDeepSubtypes.and("-Xfatal-warnings")),
41-
compileFilesInDir("tests/new", defaultOptions.and("-source", "3.1")), // just to see whether 3.1 works
41+
compileFilesInDir("tests/new", defaultOptions.and("-source", "3.2")), // just to see whether 3.2 works
4242
compileFilesInDir("tests/pos-scala2", scala2CompatMode),
4343
compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions")),
4444
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init")),

library/src/scala/runtime/stdLibPatches/language.scala

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,33 @@ object language:
165165
@compileTimeOnly("`3.1` can only be used at compile time in import statements")
166166
object `3.1`
167167

168-
/* This can be added when we go to 3.2
169168
/** Set source version to 3.2-migration.
170169
*
171-
* @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]]
170+
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
172171
*/
173172
@compileTimeOnly("`3.2-migration` can only be used at compile time in import statements")
174173
object `3.2-migration`
175174

176175
/** Set source version to 3.2
177176
*
178-
* @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]]
177+
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
179178
*/
180179
@compileTimeOnly("`3.2` can only be used at compile time in import statements")
181180
object `3.2`
181+
182+
/* This can be added when we go to 3.3
183+
/** Set source version to 3.3-migration.
184+
*
185+
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
186+
*/
187+
@compileTimeOnly("`3.3-migration` can only be used at compile time in import statements")
188+
object `3.3-migration`
189+
190+
/** Set source version to 3.3
191+
*
192+
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
193+
*/
194+
@compileTimeOnly("`3.3` can only be used at compile time in import statements")
195+
object `3.3`
182196
*/
183197
end language
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import language.`3.2-migration`

tests/pos/source-import-3-2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import language.`3.2`

0 commit comments

Comments
 (0)