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

Switch default source version to 3.6 #20895

Merged
merged 4 commits into from
Jul 4, 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
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/config/SourceVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum SourceVersion:
case `3.4-migration`, `3.4`
case `3.5-migration`, `3.5`
case `3.6-migration`, `3.6`
case `3.7-migration`, `3.7`
// !!! Keep in sync with scala.runtime.stdlibPatches.language !!!
case `future-migration`, `future`

Expand All @@ -28,7 +29,7 @@ enum SourceVersion:
def isAtMost(v: SourceVersion) = stable.ordinal <= v.ordinal

object SourceVersion extends Property.Key[SourceVersion]:
def defaultSourceVersion = `3.5`
def defaultSourceVersion = `3.6`

/** 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)
Expand Down
15 changes: 15 additions & 0 deletions library/src/scala/runtime/stdLibPatches/language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,21 @@ object language:
@compileTimeOnly("`3.6` can only be used at compile time in import statements")
object `3.6`

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

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


// !!! 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
14 changes: 2 additions & 12 deletions tests/neg/given-loop-prevention.check
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
-- Error: tests/neg/given-loop-prevention.scala:10:36 ------------------------------------------------------------------
-- [E172] Type Error: tests/neg/given-loop-prevention.scala:10:36 ------------------------------------------------------
10 | given List[Foo] = List(summon[Foo]) // error
| ^
| Result of implicit search for Foo will change.
| Current result Baz.given_Foo will be no longer eligible
| because it is not defined before the search position.
| Result with new rules: No Matching Implicit.
| To opt into the new rules, compile with `-source future` or use
| the `scala.language.future` language import.
|
| To fix the problem without the language import, you could try one of the following:
| - use a `given ... with` clause as the enclosing given,
| - rearrange definitions so that Baz.given_Foo comes earlier,
| - use an explicit argument.
| No given instance of type Foo was found for parameter x of method summon in object Predef
2 changes: 0 additions & 2 deletions tests/neg/i20415.scala

This file was deleted.

14 changes: 0 additions & 14 deletions tests/neg/i6716.check

This file was deleted.

17 changes: 6 additions & 11 deletions tests/neg/i6716.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@

trait Monad[T]:
def id: String
class Foo
object Foo {
given Monad[Foo] with { def id = "Foo" }
}

opaque type Bar = Foo
object Bar {
given Monad[Bar] = summon[Monad[Foo]] // error
given Foo with {}
given List[Foo] = List(summon[Foo]) // ok
}

object Test extends App {
println(summon[Monad[Foo]].id)
println(summon[Monad[Bar]].id)
object Baz {
@annotation.nowarn
given List[Foo] = List(summon[Foo]) // error
given Foo with {}
}
30 changes: 7 additions & 23 deletions tests/neg/i7294.check
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is the correct error to show. It should keep the following message:

-- [E007] Type Mismatch Error: tests/neg/i7294.scala:7:18 --------------------------------------------------------------
7 |  case x: T => x.g(10) // error // error
  |               ^^^^^^^
  |               Found:    Any
  |               Required: T
  |
  |               where:    T is a type in given instance f with bounds <: foo.Foo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related issue: #20992

Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
-- Error: tests/neg/i7294.scala:7:10 -----------------------------------------------------------------------------------
7 | case x: T => x.g(10) // error // error
| ^
| Result of implicit search for scala.reflect.TypeTest[Nothing, T] will change.
| Current result foo.f will be no longer eligible
| because it is not defined before the search position.
| Result with new rules: No Matching Implicit.
| To opt into the new rules, compile with `-source future` or use
| the `scala.language.future` language import.
|
| To fix the problem without the language import, you could try one of the following:
| - use a `given ... with` clause as the enclosing given,
| - rearrange definitions so that foo.f comes earlier,
| - use an explicit argument.
|
| where: T is a type in given instance f with bounds <: foo.Foo
-- [E007] Type Mismatch Error: tests/neg/i7294.scala:7:18 --------------------------------------------------------------
7 | case x: T => x.g(10) // error // error
| ^^^^^^^
| Found: Any
| Required: T
|
| where: T is a type in given instance f with bounds <: foo.Foo
-- [E007] Type Mismatch Error: tests/neg/i7294.scala:7:15 --------------------------------------------------------------
7 | case x: T => x.g(10) // error
| ^
| Found: (x : Nothing)
| Required: ?{ g: ? }
| Note that implicit conversions were not tried because the result of an implicit conversion
| must be more specific than ?{ g: [applied to (10) returning T] }
|
| longer explanation available when compiling with `-explain`
2 changes: 1 addition & 1 deletion tests/neg/i7294.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package foo
trait Foo { def g(x: Any): Any }

inline given f[T <: Foo]: T = ??? match {
case x: T => x.g(10) // error // error
case x: T => x.g(10) // error
}

@main def Test = f
48 changes: 0 additions & 48 deletions tests/neg/looping-givens.check

This file was deleted.

11 changes: 0 additions & 11 deletions tests/neg/looping-givens.scala

This file was deleted.

2 changes: 2 additions & 0 deletions tests/pos/i20415.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Foo:
given ord: Ordering[Int] = summon[Ordering[Int]]
18 changes: 10 additions & 8 deletions tests/pos/i6716.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//> using options -Xfatal-warnings -source 3.4

trait Monad[T]:
def id: String
class Foo
object Foo {
given Monad[Foo] with { def id = "Foo" }
}

opaque type Bar = Foo
object Bar {
given Foo with {}
given List[Foo] = List(summon[Foo]) // ok
given Monad[Bar] = summon[Monad[Foo]]
}

object Baz {
@annotation.nowarn
given List[Foo] = List(summon[Foo]) // gives a warning, which is suppressed
given Foo with {}
object Test extends App {
println(summon[Monad[Foo]].id)
println(summon[Monad[Bar]].id)
}
7 changes: 3 additions & 4 deletions tests/pos/looping-givens.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import language.future

class A
class B

given joint(using a: A, b: B): (A & B) = ???

def foo(using a: A, b: B) =
given aa: A = summon // error
given bb: B = summon // error
given ab: (A & B) = summon // error
given aa: A = summon // resolves to a
given bb: B = summon // resolves to b
given ab: (A & B) = summon // resolves to joint(aa, bb)
1 change: 1 addition & 0 deletions tests/pos/source-import-3-5-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import language.`3.5-migration`
1 change: 1 addition & 0 deletions tests/pos/source-import-3-5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import language.`3.5`
1 change: 1 addition & 0 deletions tests/pos/source-import-3-6-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import language.`3.6-migration`
1 change: 1 addition & 0 deletions tests/pos/source-import-3-6.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import language.`3.6`
1 change: 1 addition & 0 deletions tests/pos/source-import-3-7-migration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import language.`3.7-migration`
1 change: 1 addition & 0 deletions tests/pos/source-import-3-7.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import language.`3.7`
2 changes: 1 addition & 1 deletion tests/run/i6716.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//> using options -Xfatal-warnings -source future
//> using options -Xfatal-warnings

trait Monad[T]:
def id: String
Expand Down
Loading