From aad6f7d1c091c6a59f44ae5b56bffd180f22b64a Mon Sep 17 00:00:00 2001 From: Hamza REMMAL Date: Wed, 3 Jul 2024 14:26:25 +0200 Subject: [PATCH] Adapt the test suite to scala 3.6 --- tests/neg/given-loop-prevention.check | 14 ++------ tests/neg/i20415.scala | 2 -- tests/neg/i6716.check | 14 -------- tests/neg/i6716.scala | 17 ++++------ tests/neg/i7294.check | 30 ++++------------- tests/neg/i7294.scala | 2 +- tests/neg/looping-givens.check | 48 --------------------------- tests/neg/looping-givens.scala | 11 ------ tests/pos/i20415.scala | 2 ++ tests/pos/i6716.scala | 18 +++++----- tests/pos/looping-givens.scala | 7 ++-- tests/run/i6716.scala | 2 +- 12 files changed, 32 insertions(+), 135 deletions(-) delete mode 100644 tests/neg/i20415.scala delete mode 100644 tests/neg/i6716.check delete mode 100644 tests/neg/looping-givens.check delete mode 100644 tests/neg/looping-givens.scala create mode 100644 tests/pos/i20415.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/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