Skip to content
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

deprecate 3.1-migration, err on import #14978

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/config/SourceVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ enum SourceVersion:

object SourceVersion extends Property.Key[SourceVersion]:

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

/** language versions that the compiler recognises. */
val validSourceVersionNames = values.toList.map(_.toString.toTermName)

/** All source versions that can be recognised from a language import. e.g. `import language.3.1` */
val allSourceVersionNames = validSourceVersionNames ::: illegalSourceVersionNames
end SourceVersion
9 changes: 9 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,15 @@ object Parsers {
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 if illegalSourceVersionNames.contains(imported) then
val candidate =
val nonMigration = imported.toString.replace("-migration", "")
validSourceVersionNames.find(_.show == nonMigration)
val baseMsg = i"`$imported` is not a valid source version"
val msg = candidate match
case Some(member) => i"$baseMsg, did you mean language.`$member`?"
case _ => baseMsg
syntaxError(msg, id.span)
else
ctx.compilationUnit.sourceVersion = Some(SourceVersion.valueOf(imported.toString))
case None =>
Expand Down
3 changes: 3 additions & 0 deletions library/src/scala/runtime/stdLibPatches/language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ object language:
object `3.0`

/** Set source version to 3.1-migration.
*
* This is a no-op, and should not be used. A syntax error will be reported upon import.
*
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
*/
@compileTimeOnly("`3.1-migration` can only be used at compile time in import statements")
@deprecated("`3.1-migration` is not valid, use `3.1` instead", since = "3.2")
object `3.1-migration`

/** Set source version to 3.1
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i12457.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import language.`3.1-migration`
import language.`3.1`

trait X [ X <: Z , Z >: X [ R ] ] // error
4 changes: 4 additions & 0 deletions tests/neg/source-import-3-1-migration.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/source-import-3-1-migration.scala:1:16 -------------------------------------------------------------
1 |import language.`3.1-migration` // error
| ^^^^^^^^^^^^^^^
| `3.1-migration` is not a valid source version, did you mean language.`3.1`?
1 change: 1 addition & 0 deletions tests/neg/source-import-3-1-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import language.`3.1-migration` // error
1 change: 0 additions & 1 deletion tests/pos/source-import-3-1-migration.scala

This file was deleted.