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

Sync language.scala with main and backport "Add tests for context bounds migration" #19515

Merged
merged 3 commits into from
Jan 24, 2024
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
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.
Loading