diff --git a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala index 935b95003729..caf1187614b7 100644 --- a/compiler/src/dotty/tools/dotc/config/SourceVersion.scala +++ b/compiler/src/dotty/tools/dotc/config/SourceVersion.scala @@ -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` @@ -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) diff --git a/library/src/scala/runtime/stdLibPatches/language.scala b/library/src/scala/runtime/stdLibPatches/language.scala index d89bd9dcf72e..9e08b82b4082 100644 --- a/library/src/scala/runtime/stdLibPatches/language.scala +++ b/library/src/scala/runtime/stdLibPatches/language.scala @@ -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` diff --git a/tests/neg/given-loop-prevention.check b/tests/neg/given-loop-prevention.check index 460adf03be49..cbaeec2474f4 100644 --- a/tests/neg/given-loop-prevention.check +++ b/tests/neg/given-loop-prevention.check @@ -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 diff --git a/tests/neg/i20415.scala b/tests/neg/i20415.scala deleted file mode 100644 index 14582e40aa9d..000000000000 --- a/tests/neg/i20415.scala +++ /dev/null @@ -1,2 +0,0 @@ -class Foo: - given ord: Ordering[Int] = summon[Ordering[Int]] // error diff --git a/tests/neg/i6716.check b/tests/neg/i6716.check deleted file mode 100644 index 0144f539f53c..000000000000 --- a/tests/neg/i6716.check +++ /dev/null @@ -1,14 +0,0 @@ --- Error: tests/neg/i6716.scala:11:39 ---------------------------------------------------------------------------------- -11 | given Monad[Bar] = summon[Monad[Foo]] // error - | ^ - | Result of implicit search for Monad[Foo] will change. - | Current result Bar.given_Monad_Bar will be no longer eligible - | because it is not defined before the search position. - | Result with new rules: Foo.given_Monad_Foo. - | 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 Bar.given_Monad_Bar comes earlier, - | - use an explicit argument. diff --git a/tests/neg/i6716.scala b/tests/neg/i6716.scala index 8b37d4e223ac..eece8af9e560 100644 --- a/tests/neg/i6716.scala +++ b/tests/neg/i6716.scala @@ -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 {} } diff --git a/tests/neg/i7294.check b/tests/neg/i7294.check index d6e559997f78..30c076470899 100644 --- a/tests/neg/i7294.check +++ b/tests/neg/i7294.check @@ -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` diff --git a/tests/neg/i7294.scala b/tests/neg/i7294.scala index fbb00f9b7e89..2725109e79e8 100644 --- a/tests/neg/i7294.scala +++ b/tests/neg/i7294.scala @@ -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 diff --git a/tests/neg/looping-givens.check b/tests/neg/looping-givens.check deleted file mode 100644 index 1e7ee08d79df..000000000000 --- a/tests/neg/looping-givens.check +++ /dev/null @@ -1,48 +0,0 @@ --- Error: tests/neg/looping-givens.scala:9:22 -------------------------------------------------------------------------- -9 | given aa: A = summon // error - | ^ - | Result of implicit search for T will change. - | Current result ab will be no longer eligible - | because it is not defined before the search position. - | Result with new rules: a. - | 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 ab comes earlier, - | - use an explicit argument. - | - | where: T is a type variable with constraint <: A --- Error: tests/neg/looping-givens.scala:10:22 ------------------------------------------------------------------------- -10 | given bb: B = summon // error - | ^ - | Result of implicit search for T will change. - | Current result ab will be no longer eligible - | because it is not defined before the search position. - | Result with new rules: b. - | 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 ab comes earlier, - | - use an explicit argument. - | - | where: T is a type variable with constraint <: B --- Error: tests/neg/looping-givens.scala:11:28 ------------------------------------------------------------------------- -11 | given ab: (A & B) = summon // error - | ^ - | Result of implicit search for T will change. - | Current result ab will be no longer eligible - | because it is not defined before the search position. - | Result with new rules: Search Failure: joint(ab, ab). - | 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 ab comes earlier, - | - use an explicit argument. - | - | where: T is a type variable with constraint <: A & B diff --git a/tests/neg/looping-givens.scala b/tests/neg/looping-givens.scala deleted file mode 100644 index 57dc95f99aab..000000000000 --- a/tests/neg/looping-givens.scala +++ /dev/null @@ -1,11 +0,0 @@ -//> options -source 3.4 - -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 diff --git a/tests/pos/i20415.scala b/tests/pos/i20415.scala new file mode 100644 index 000000000000..500dcb83ba15 --- /dev/null +++ b/tests/pos/i20415.scala @@ -0,0 +1,2 @@ +class Foo: + given ord: Ordering[Int] = summon[Ordering[Int]] diff --git a/tests/pos/i6716.scala b/tests/pos/i6716.scala index f02559af1e82..617adc3c09f0 100644 --- a/tests/pos/i6716.scala +++ b/tests/pos/i6716.scala @@ -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) } diff --git a/tests/pos/looping-givens.scala b/tests/pos/looping-givens.scala index 0e615c8251df..d7d086358099 100644 --- a/tests/pos/looping-givens.scala +++ b/tests/pos/looping-givens.scala @@ -1,4 +1,3 @@ -import language.future class A class B @@ -6,6 +5,6 @@ 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) diff --git a/tests/pos/source-import-3-5-migration.scala b/tests/pos/source-import-3-5-migration.scala new file mode 100644 index 000000000000..d47e0307473e --- /dev/null +++ b/tests/pos/source-import-3-5-migration.scala @@ -0,0 +1 @@ +import language.`3.5-migration` \ No newline at end of file diff --git a/tests/pos/source-import-3-5.scala b/tests/pos/source-import-3-5.scala new file mode 100644 index 000000000000..615ae8638c24 --- /dev/null +++ b/tests/pos/source-import-3-5.scala @@ -0,0 +1 @@ +import language.`3.5` \ No newline at end of file diff --git a/tests/pos/source-import-3-6-migration.scala b/tests/pos/source-import-3-6-migration.scala new file mode 100644 index 000000000000..d566362cfe41 --- /dev/null +++ b/tests/pos/source-import-3-6-migration.scala @@ -0,0 +1 @@ +import language.`3.6-migration` \ No newline at end of file diff --git a/tests/pos/source-import-3-6.scala b/tests/pos/source-import-3-6.scala new file mode 100644 index 000000000000..1d85eea86f54 --- /dev/null +++ b/tests/pos/source-import-3-6.scala @@ -0,0 +1 @@ +import language.`3.6` \ No newline at end of file diff --git a/tests/pos/source-import-3-7-migration.scala b/tests/pos/source-import-3-7-migration.scala new file mode 100644 index 000000000000..2e80fcb0bab2 --- /dev/null +++ b/tests/pos/source-import-3-7-migration.scala @@ -0,0 +1 @@ +import language.`3.7-migration` \ No newline at end of file diff --git a/tests/pos/source-import-3-7.scala b/tests/pos/source-import-3-7.scala new file mode 100644 index 000000000000..7fa68fd496f6 --- /dev/null +++ b/tests/pos/source-import-3-7.scala @@ -0,0 +1 @@ +import language.`3.7` \ No newline at end of file diff --git a/tests/run/i6716.scala b/tests/run/i6716.scala index 3bef45ac7465..e793381cce1c 100644 --- a/tests/run/i6716.scala +++ b/tests/run/i6716.scala @@ -1,4 +1,4 @@ -//> using options -Xfatal-warnings -source future +//> using options -Xfatal-warnings trait Monad[T]: def id: String