From 83bfea9251d5298b7c2d033c67cfc074dd9d78af Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Fri, 4 Mar 2022 17:10:36 +0100 Subject: [PATCH 1/3] introduce infrastructure for 3.2 language features --- .../src/dotty/tools/dotc/config/Feature.scala | 11 +-- .../tools/dotc/config/ScalaSettings.scala | 11 ++- .../tools/dotc/config/SourceVersion.scala | 53 +++++++++- .../dotty/tools/dotc/parsing/Parsers.scala | 4 +- compiler/src/dotty/tools/dotc/report.scala | 5 +- .../dotty/tools/dotc/CompilationTests.scala | 2 +- .../tools/dotc/config/SourceVersionTest.scala | 98 +++++++++++++++++++ .../runtime/stdLibPatches/language.scala | 20 +++- tests/pos/source-import-3-2-migration.scala | 1 + tests/pos/source-import-3-2.scala | 1 + 10 files changed, 184 insertions(+), 22 deletions(-) create mode 100644 compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala create mode 100644 tests/pos/source-import-3-2-migration.scala create mode 100644 tests/pos/source-import-3-2.scala diff --git a/compiler/src/dotty/tools/dotc/config/Feature.scala b/compiler/src/dotty/tools/dotc/config/Feature.scala index 04c7b5872204..1768d5749f84 100644 --- a/compiler/src/dotty/tools/dotc/config/Feature.scala +++ b/compiler/src/dotty/tools/dotc/config/Feature.scala @@ -76,7 +76,7 @@ object Feature: def scala2ExperimentalMacroEnabled(using Context) = enabled(scala2macros) def sourceVersionSetting(using Context): SourceVersion = - SourceVersion.valueOf(ctx.settings.source.value) + SourceVersion.lookupSourceVersion.fromSetting(ctx.settings.source.value) def sourceVersion(using Context): SourceVersion = ctx.compilationUnit.sourceVersion match @@ -85,14 +85,11 @@ object Feature: def migrateTo3(using Context): Boolean = sourceVersion == `3.0-migration` - /** If current source migrates to `version`, issue given warning message + /** If current source migrates to a version in the series denoted by `version`, issue given warning message * and return `true`, otherwise return `false`. */ - def warnOnMigration(msg: Message, pos: SrcPos, - version: SourceVersion)(using Context): Boolean = - if sourceVersion.isMigrating && sourceVersion.stable == version - || (version == `3.0` || version == `3.1` || version == `3.2`) && migrateTo3 - then + def warnOnMigration(msg: Message, pos: SrcPos, version: SourceVersion)(using Context): Boolean = + if sourceVersion.isMigrating && sourceVersion.series == version.series then report.migrationWarning(msg, pos) true else diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index fa364110b052..7e5273c9086a 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -5,6 +5,7 @@ import scala.language.unsafeNulls import dotty.tools.dotc.config.PathResolver.Defaults import dotty.tools.dotc.config.Settings.{Setting, SettingGroup} +import dotty.tools.dotc.config.SourceVersion import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.rewrites.Rewrites import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory} @@ -51,7 +52,15 @@ trait AllScalaSettings extends CommonScalaSettings, PluginSettings, VerboseSetti /* Path related settings */ val semanticdbTarget: Setting[String] = PathSetting("-semanticdb-target", "Specify an alternative output directory for SemanticDB files.", "") - 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")) + private val SourceVersionOptions = + SourceVersion + .lookupSourceVersion.fromSetting + .toList + // we want `3.1-migration` to be before `3.1`, but both map to same SourceVersion + .sortBy((key, version) => (version.ordinal, !key.endsWith("-migration"))) + .map((key, _) => key) + + val source: Setting[String] = ChoiceSetting("-source", "source version", "source version", SourceVersionOptions, SourceVersion.defaultSourceVersion.toString, aliases = List("--source")) val uniqid: Setting[Boolean] = BooleanSetting("-uniqid", "Uniquely tag all identifiers in debugging output.", aliases = List("--unique-id")) 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")) val fromTasty: Setting[Boolean] = BooleanSetting("-from-tasty", "Compile classes from tasty files. The arguments are .tasty or .jar files.", aliases = List("--from-tasty")) diff --git a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala index 9361c7e6774d..ad80276f5d1a 100644 --- a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala @@ -5,17 +5,60 @@ package config import core.Decorators.* import util.Property +import scala.annotation.threadUnsafe +import dotty.tools.dotc.core.Names.Name + +/** Enum expressing series of source versions, + * where each series begins by a migration version, followed by a series of stable versions. + * e.g. `3.0-migration`, `3.0`, `3.1` make one series, `3.0`, as they describe the same semantics. + * `future-migration`, then begins the another series of stable versions, `future`, because in this version we + * enable more features. + * + * @note This enum does not need to correspond to the scala.language imports. E.g. if a user imports + * `scala.language.3.1-migration`, the SourceVersion will be set to `3.1` (see `lookupSourceVersion`). + * + */ enum SourceVersion: - case `3.0-migration`, `3.0`, `3.1`, `3.2`, `future-migration`, `future` + 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. + case `3.2`, `3.2-migration` // !!! DELETE `3.2-migration` BEFORE RELEASING 3.2.0 if we do not enable features from `future` + case `future-migration`, `future` val isMigrating: Boolean = toString.endsWith("-migration") - def stable: SourceVersion = - if isMigrating then SourceVersion.values(ordinal + 1) else this + private inline def nextVersion: SourceVersion = SourceVersion.fromOrdinal(ordinal + 1) + private inline def previousVersion: SourceVersion = SourceVersion.fromOrdinal(ordinal - 1) + + @threadUnsafe lazy val series: SourceVersion = + if isMigrating then nextVersion else previousVersion.series - def isAtLeast(v: SourceVersion) = stable.ordinal >= v.ordinal + def isAtLeast(v: SourceVersion) = this.series.ordinal >= v.series.ordinal object SourceVersion extends Property.Key[SourceVersion]: + def defaultSourceVersion = `3.2` + + object lookupSourceVersion: + + /** A map from with keys matching the `scala.language` imports, + * and values being the corresponding `SourceVersion`, or the next + * stable version if the key ends with `-migration` and no matching SourceVersion exists. + */ + val fromSetting: Map[String, SourceVersion] = + val (migratingVersions, stableVersions) = values.partition(_.isMigrating) + val entries = stableVersions.flatMap(stable => + val migratingKey = s"${stable}-migration" + val migratingEntry = + migratingVersions.find(_.toString == migratingKey) match + case Some(migrating) => migratingKey -> migrating + case _ => migratingKey -> stable + val stableEntry = stable.toString -> stable + stableEntry :: migratingEntry :: Nil + ) + Map.from(entries) + + /** An immutable array with keys matching the `scala.language` imports + * corresponding to source versions + */ + val fromImport: IArray[Name] = + IArray.from(fromSetting.iterator.map((key, _) => key.toTermName)) - val allSourceVersionNames = values.toList.map(_.toString.toTermName) end SourceVersion diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 7a5620be0415..b91a8531145b 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3140,14 +3140,14 @@ object Parsers { in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol) for case ImportSelector(id @ Ident(imported), EmptyTree, _) <- selectors - if allSourceVersionNames.contains(imported) + if lookupSourceVersion.fromImport.contains(imported) do if !outermost then syntaxError(i"source version import is only allowed at the toplevel", id.span) else if ctx.compilationUnit.sourceVersion.isDefined then syntaxError(i"duplicate source version import", id.span) else - ctx.compilationUnit.sourceVersion = Some(SourceVersion.valueOf(imported.toString)) + ctx.compilationUnit.sourceVersion = Some(lookupSourceVersion.fromSetting(imported.toString)) case None => imp diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 94a7b4f318fa..97637e56c675 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -67,10 +67,9 @@ object report: error(ex.toMessage, pos, sticky = true) if ctx.settings.YdebugTypeError.value then ex.printStackTrace() - def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition, - from: SourceVersion)(using Context): Unit = + def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition, from: SourceVersion)(using Context): Unit = if sourceVersion.isAtLeast(from) then - if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos) + if sourceVersion.isMigrating && sourceVersion.series == from.series then migrationWarning(msg, pos) else error(msg, pos) def restrictionError(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit = diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index f8089dfcabfa..46df97937f46 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -38,7 +38,7 @@ class CompilationTests { compileFilesInDir("tests/pos-special/spec-t5545", defaultOptions), compileFilesInDir("tests/pos-special/strawman-collections", allowDeepSubtypes), compileFilesInDir("tests/pos-special/isInstanceOf", allowDeepSubtypes.and("-Xfatal-warnings")), - compileFilesInDir("tests/new", defaultOptions.and("-source", "3.1")), // just to see whether 3.1 works + compileFilesInDir("tests/new", defaultOptions.and("-source", "3.2")), // just to see whether 3.2 works compileFilesInDir("tests/pos-scala2", scala2CompatMode), compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions")), compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init")), diff --git a/compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala b/compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala new file mode 100644 index 000000000000..ea91d6720cd1 --- /dev/null +++ b/compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala @@ -0,0 +1,98 @@ +package dotty.tools.dotc.config + +import dotty.tools.dotc.core.Decorators.* + +import org.junit.Test +import org.junit.Assert.* + +import SourceVersionTest.* + +class SourceVersionTest: + + @Test def `importedVersion`: Unit = + assertEquals(SourceVersion.`3.0-migration`, importLanguageDot("3.0-migration")) + assertEquals(SourceVersion.`3.0`, importLanguageDot("3.0")) + + // crucial that here `import scala.language.3.1-migration` sets the source version to `3.1` + assertEquals(SourceVersion.`3.1`, importLanguageDot("3.1-migration")) + + assertEquals(SourceVersion.`3.1`, importLanguageDot("3.1")) + assertEquals(SourceVersion.`3.2-migration`, importLanguageDot("3.2-migration")) + assertEquals(SourceVersion.`3.2`, importLanguageDot("3.2")) + assertEquals(SourceVersion.`future-migration`, importLanguageDot("future-migration")) + assertEquals(SourceVersion.`future`, importLanguageDot("future")) + + @Test def `series`: Unit = + assertEquals(SourceVersion.`3.0`, SourceVersion.`3.0-migration`.series) + assertEquals(SourceVersion.`3.0`, SourceVersion.`3.0`.series) + assertEquals(SourceVersion.`3.0`, SourceVersion.`3.1`.series) + assertEquals(SourceVersion.`3.2`, SourceVersion.`3.2-migration`.series) + assertEquals(SourceVersion.`3.2`, SourceVersion.`3.2`.series) + assertEquals(SourceVersion.`future`, SourceVersion.`future-migration`.series) + assertEquals(SourceVersion.`future`, SourceVersion.`future`.series) + + @Test def `isAtLeast 3.0`: Unit = + // trues + assertTrue(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.1`)) + assertTrue(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.0`)) + assertTrue(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.0-migration`)) + assertTrue(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.1`)) + assertTrue(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.0`)) + assertTrue(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.0-migration`)) + assertTrue(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.1`)) + assertTrue(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.0`)) + assertTrue(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.0-migration`)) + // falses + assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`future`)) + assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`future-migration`)) + assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.2`)) + assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.2-migration`)) + assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`future`)) + assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`future-migration`)) + assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.2`)) + assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.2-migration`)) + assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`future`)) + assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`future-migration`)) + assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.2`)) + assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.2-migration`)) + + @Test def `isAtLeast 3.2`: Unit = + // trues + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.2`)) + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.2-migration`)) + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.1`)) + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0`)) + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0-migration`)) + assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.2`)) + assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.2-migration`)) + assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.1`)) + assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.0`)) + assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.0-migration`)) + // falses + assertFalse(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`future`)) + assertFalse(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`future-migration`)) + assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future`)) + assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future-migration`)) + + @Test def `isAtLeast future`: Unit = + // trues + assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`future`)) + assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`future-migration`)) + assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.2`)) + assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.2-migration`)) + assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.1`)) + assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.0`)) + assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.0-migration`)) + assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`future`)) + assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`future-migration`)) + assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.2`)) + assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.2-migration`)) + assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.1`)) + assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.0`)) + assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.0-migration`)) + // no falses + +object SourceVersionTest: + + def importLanguageDot(feature: String): SourceVersion = + SourceVersion.lookupSourceVersion.fromSetting(feature) diff --git a/library/src/scala/runtime/stdLibPatches/language.scala b/library/src/scala/runtime/stdLibPatches/language.scala index 7c8c116a106e..fde66a6aaf2b 100644 --- a/library/src/scala/runtime/stdLibPatches/language.scala +++ b/library/src/scala/runtime/stdLibPatches/language.scala @@ -162,19 +162,33 @@ object language: @compileTimeOnly("`3.1` can only be used at compile time in import statements") object `3.1` -/* This can be added when we go to 3.2 /** Set source version to 3.2-migration. * - * @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]] + * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] */ @compileTimeOnly("`3.2-migration` can only be used at compile time in import statements") object `3.2-migration` /** Set source version to 3.2 * - * @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]] + * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] */ @compileTimeOnly("`3.2` can only be used at compile time in import statements") object `3.2` + +/* This can be added when we go to 3.3 + /** Set source version to 3.3-migration. + * + * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] + */ + @compileTimeOnly("`3.3-migration` can only be used at compile time in import statements") + object `3.3-migration` + + /** Set source version to 3.3 + * + * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] + */ + @compileTimeOnly("`3.3` can only be used at compile time in import statements") + object `3.3` */ end language diff --git a/tests/pos/source-import-3-2-migration.scala b/tests/pos/source-import-3-2-migration.scala new file mode 100644 index 000000000000..4d5e0957298e --- /dev/null +++ b/tests/pos/source-import-3-2-migration.scala @@ -0,0 +1 @@ +import language.`3.2-migration` diff --git a/tests/pos/source-import-3-2.scala b/tests/pos/source-import-3-2.scala new file mode 100644 index 000000000000..3bdf8d028865 --- /dev/null +++ b/tests/pos/source-import-3-2.scala @@ -0,0 +1 @@ +import language.`3.2` From b5a98e7aa28e2dd51221948b9ec393be278a7c20 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Tue, 15 Mar 2022 16:07:42 +0100 Subject: [PATCH 2/3] remove 3.2 language imports --- .../runtime/stdLibPatches/language.scala | 20 +++---------------- tests/pos/source-import-3-2-migration.scala | 1 - tests/pos/source-import-3-2.scala | 1 - 3 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 tests/pos/source-import-3-2-migration.scala delete mode 100644 tests/pos/source-import-3-2.scala diff --git a/library/src/scala/runtime/stdLibPatches/language.scala b/library/src/scala/runtime/stdLibPatches/language.scala index fde66a6aaf2b..7c8c116a106e 100644 --- a/library/src/scala/runtime/stdLibPatches/language.scala +++ b/library/src/scala/runtime/stdLibPatches/language.scala @@ -162,33 +162,19 @@ object language: @compileTimeOnly("`3.1` can only be used at compile time in import statements") object `3.1` +/* This can be added when we go to 3.2 /** Set source version to 3.2-migration. * - * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] + * @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]] */ @compileTimeOnly("`3.2-migration` can only be used at compile time in import statements") object `3.2-migration` /** Set source version to 3.2 * - * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] + * @see [[https://scalacenter.github.io/scala-3-migration-guide/docs/scala-3-migration-mode]] */ @compileTimeOnly("`3.2` can only be used at compile time in import statements") object `3.2` - -/* This can be added when we go to 3.3 - /** Set source version to 3.3-migration. - * - * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] - */ - @compileTimeOnly("`3.3-migration` can only be used at compile time in import statements") - object `3.3-migration` - - /** Set source version to 3.3 - * - * @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]] - */ - @compileTimeOnly("`3.3` can only be used at compile time in import statements") - object `3.3` */ end language diff --git a/tests/pos/source-import-3-2-migration.scala b/tests/pos/source-import-3-2-migration.scala deleted file mode 100644 index 4d5e0957298e..000000000000 --- a/tests/pos/source-import-3-2-migration.scala +++ /dev/null @@ -1 +0,0 @@ -import language.`3.2-migration` diff --git a/tests/pos/source-import-3-2.scala b/tests/pos/source-import-3-2.scala deleted file mode 100644 index 3bdf8d028865..000000000000 --- a/tests/pos/source-import-3-2.scala +++ /dev/null @@ -1 +0,0 @@ -import language.`3.2` From 44f164f09d3eb1a3f1b25fe0f86e4316ca8b6421 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Mon, 7 Mar 2022 13:10:20 +0100 Subject: [PATCH 3/3] remove 3.2-migration revert this commit if we actually need a 3.2 migration, i.e. because we enable strict pattern matching --- .../tools/dotc/config/SourceVersion.scala | 3 +- .../tools/dotc/config/SourceVersionTest.scala | 65 +++++++++++-------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala index ad80276f5d1a..abe8ee0a31f4 100644 --- a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala @@ -20,7 +20,8 @@ import dotty.tools.dotc.core.Names.Name */ enum SourceVersion: 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. - case `3.2`, `3.2-migration` // !!! DELETE `3.2-migration` BEFORE RELEASING 3.2.0 if we do not enable features from `future` + // case `3.2-migration` // !!! UNCOMMENT `3.2-migration` BEFORE RELEASING 3.2.0 if we enable features from `future` + case `3.2` case `future-migration`, `future` val isMigrating: Boolean = toString.endsWith("-migration") diff --git a/compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala b/compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala index ea91d6720cd1..ec8c03e43b9b 100644 --- a/compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala +++ b/compiler/test/dotty/tools/dotc/config/SourceVersionTest.scala @@ -17,7 +17,8 @@ class SourceVersionTest: assertEquals(SourceVersion.`3.1`, importLanguageDot("3.1-migration")) assertEquals(SourceVersion.`3.1`, importLanguageDot("3.1")) - assertEquals(SourceVersion.`3.2-migration`, importLanguageDot("3.2-migration")) + // assertEquals(SourceVersion.`3.2-migration`, importLanguageDot("3.2-migration")) // uncomment when we introduce `3.2-migration` + assertEquals(SourceVersion.`3.2`, importLanguageDot("3.2-migration")) // delete when we introduce `3.2-migration` assertEquals(SourceVersion.`3.2`, importLanguageDot("3.2")) assertEquals(SourceVersion.`future-migration`, importLanguageDot("future-migration")) assertEquals(SourceVersion.`future`, importLanguageDot("future")) @@ -26,67 +27,79 @@ class SourceVersionTest: assertEquals(SourceVersion.`3.0`, SourceVersion.`3.0-migration`.series) assertEquals(SourceVersion.`3.0`, SourceVersion.`3.0`.series) assertEquals(SourceVersion.`3.0`, SourceVersion.`3.1`.series) - assertEquals(SourceVersion.`3.2`, SourceVersion.`3.2-migration`.series) - assertEquals(SourceVersion.`3.2`, SourceVersion.`3.2`.series) + // assertEquals(SourceVersion.`3.2`, SourceVersion.`3.2-migration`.series) // uncomment when we introduce `3.2-migration` + // assertEquals(SourceVersion.`3.2`, SourceVersion.`3.2`.series) // uncomment when we introduce `3.2-migration` + assertEquals(SourceVersion.`3.0`, SourceVersion.`3.2`.series) // delete when we introduce `3.2-migration` assertEquals(SourceVersion.`future`, SourceVersion.`future-migration`.series) assertEquals(SourceVersion.`future`, SourceVersion.`future`.series) @Test def `isAtLeast 3.0`: Unit = // trues + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.2`)) // delete when we introduce `3.2-migration` + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.1`)) // delete when we introduce `3.2-migration` + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0`)) // delete when we introduce `3.2-migration` + assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0-migration`)) // delete when we introduce `3.2-migration` + assertTrue(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.2`)) // delete when we introduce `3.2-migration` assertTrue(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.1`)) assertTrue(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.0`)) assertTrue(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.0-migration`)) + assertTrue(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.2`)) // delete when we introduce `3.2-migration` assertTrue(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.1`)) assertTrue(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.0`)) assertTrue(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.0-migration`)) + assertTrue(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.2`)) // delete when we introduce `3.2-migration` assertTrue(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.1`)) assertTrue(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.0`)) assertTrue(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.0-migration`)) + + // falses assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`future`)) assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`future-migration`)) - assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.2`)) - assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.2-migration`)) + // assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.2`)) // uncomment when we introduce `3.2-migration` + // assertFalse(SourceVersion.`3.0-migration`.isAtLeast(SourceVersion.`3.2-migration`)) // uncomment when we introduce `3.2-migration` assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`future`)) assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`future-migration`)) - assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.2`)) - assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.2-migration`)) + // assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.2`)) // uncomment when we introduce `3.2-migration` + // assertFalse(SourceVersion.`3.0`.isAtLeast(SourceVersion.`3.2-migration`)) // uncomment when we introduce `3.2-migration` assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`future`)) assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`future-migration`)) - assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.2`)) - assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.2-migration`)) + // assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.2`)) // uncomment when we introduce `3.2-migration` + // assertFalse(SourceVersion.`3.1`.isAtLeast(SourceVersion.`3.2-migration`)) // uncomment when we introduce `3.2-migration + assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future`)) // delete when we introduce `3.2-migration` + assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future-migration`)) // delete when we introduce `3.2-migration` - @Test def `isAtLeast 3.2`: Unit = + // @Test def `isAtLeast 3.2`: Unit = // uncomment when we introduce `3.2-migration` // trues - assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.2`)) - assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.2-migration`)) - assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.1`)) - assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0`)) - assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0-migration`)) - assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.2`)) - assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.2-migration`)) - assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.1`)) - assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.0`)) - assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.0-migration`)) + // assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.2`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.2-migration`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.1`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2`.isAtLeast(SourceVersion.`3.0-migration`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.2`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.2-migration`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.1`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.0`)) // uncomment when we introduce `3.2-migration` + // assertTrue(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`3.0-migration`)) // uncomment when we introduce `3.2-migration` // falses - assertFalse(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`future`)) - assertFalse(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`future-migration`)) - assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future`)) - assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future-migration`)) + // assertFalse(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`future`)) // uncomment when we introduce `3.2-migration` + // assertFalse(SourceVersion.`3.2-migration`.isAtLeast(SourceVersion.`future-migration`)) // uncomment when we introduce `3.2-migration` + // assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future`)) // uncomment when we introduce `3.2-migration` + // assertFalse(SourceVersion.`3.2`.isAtLeast(SourceVersion.`future-migration`)) // uncomment when we introduce `3.2-migration` @Test def `isAtLeast future`: Unit = // trues assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`future`)) assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`future-migration`)) assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.2`)) - assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.2-migration`)) + // assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.2-migration`)) assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.1`)) assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.0`)) assertTrue(SourceVersion.`future`.isAtLeast(SourceVersion.`3.0-migration`)) assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`future`)) assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`future-migration`)) assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.2`)) - assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.2-migration`)) + // assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.2-migration`)) assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.1`)) assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.0`)) assertTrue(SourceVersion.`future-migration`.isAtLeast(SourceVersion.`3.0-migration`))