Skip to content

Commit

Permalink
Sync language.scala with main and backport "Add tests for context bou…
Browse files Browse the repository at this point in the history
…nds migration" (#19515)

Backports #19510
  • Loading branch information
Kordyjan authored Jan 24, 2024
2 parents a220621 + c76806c commit 600c525
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object MigrationVersion:

val AscriptionAfterPattern = MigrationVersion(`3.3`, future)

val ExplicitContextBoundArgument = MigrationVersion(`3.4`, future)
val ExplicitContextBoundArgument = MigrationVersion(`3.4`, `3.5`)

val AlphanumericInfix = MigrationVersion(`3.4`, future)
val RemoveThisQualifier = MigrationVersion(`3.4`, future)
Expand Down
14 changes: 14 additions & 0 deletions library/src/scala/runtime/stdLibPatches/language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ object language:
@compileTimeOnly("`3.4` can only be used at compile time in import statements")
object `3.4`

/** Set source version to 3.5-migration.
*
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
*/
@compileTimeOnly("`3.5-migration` can only be used at compile time in import statements")
object `3.5-migration`

/** Set source version to 3.5
*
* @see [[https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html]]
*/
@compileTimeOnly("`3.5` can only be used at compile time in import statements")
object `3.5`

// !!! Keep in sync with dotty.tools.dotc.config.SourceVersion !!!
// Also add tests in `tests/pos/source-import-3-x.scala` and `tests/pos/source-import-3-x-migration.scala`

Expand Down
6 changes: 6 additions & 0 deletions tests/neg/context-bounds-migration-3.5.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Error: tests/neg/context-bounds-migration-3.5.scala:9:2 -------------------------------------------------------------
9 | foo(C[Int]()) // error
| ^^^
| Context bounds will map to context parameters.
| A `using` clause is needed to pass explicit arguments to them.
| This code can be rewritten automatically under -rewrite -source 3.4-migration.
10 changes: 10 additions & 0 deletions tests/neg/context-bounds-migration-3.5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//> using options -source 3.5

class C[T]
def foo[X: C] = ()

given [T]: C[T] = C[T]()

def Test =
foo(C[Int]()) // error
foo(using C[Int]()) // ok
6 changes: 6 additions & 0 deletions tests/neg/context-bounds-migration-future.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E050] Type Error: tests/neg/context-bounds-migration-future.scala:9:2 ----------------------------------------------
9 | foo(C[Int]()) // error
| ^^^
| method foo does not take more parameters
|
| longer explanation available when compiling with `-explain`
10 changes: 10 additions & 0 deletions tests/neg/context-bounds-migration-future.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//> using options -source future

class C[T]
def foo[X: C] = ()

given [T]: C[T] = C[T]()

def Test =
foo(C[Int]()) // error
foo(using C[Int]()) // ok
6 changes: 6 additions & 0 deletions tests/warn/context-bounds-migration-3.4.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Warning: tests/warn/context-bounds-migration-3.4.scala:9:2 ----------------------------------------------------------
9 | foo(C[Int]()) // warn
| ^^^
| Context bounds will map to context parameters.
| A `using` clause is needed to pass explicit arguments to them.
| This code can be rewritten automatically under -rewrite -source 3.4-migration.
File renamed without changes.

0 comments on commit 600c525

Please sign in to comment.