Skip to content

Commit

Permalink
Adapt the tests to Scala 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal committed May 21, 2024
1 parent c796bcf commit de46c7d
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 101 deletions.
2 changes: 1 addition & 1 deletion library/src/scala/quoted/ToExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object ToExpr {
/** Default implementation of `ToExpr[Array[T]]` */
given ArrayToExpr[T: Type: ToExpr: ClassTag]: ToExpr[Array[T]] with {
def apply(arr: Array[T])(using Quotes): Expr[Array[T]] =
'{ Array[T](${Expr(arr.toSeq)}*)(${Expr(summon[ClassTag[T]])}) }
'{ Array[T](${Expr(arr.toSeq)}*)(using ${Expr(summon[ClassTag[T]])}) }
}

/** Default implementation of `ToExpr[Array[Boolean]]` */
Expand Down
14 changes: 14 additions & 0 deletions tests/neg/given-loop-prevention.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- 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.
12 changes: 12 additions & 0 deletions tests/neg/given-loop-prevention.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

class Foo

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

object Baz {
given List[Foo] = List(summon[Foo]) // error
given Foo with {}
}
6 changes: 2 additions & 4 deletions tests/neg/i6716.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Warning: tests/neg/i6716.scala:12:39 --------------------------------------------------------------------------------
12 | given Monad[Bar] = summon[Monad[Foo]] // warn
-- 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
Expand All @@ -12,5 +12,3 @@
| - use a `given ... with` clause as the enclosing given,
| - rearrange definitions so that Bar.given_Monad_Bar comes earlier,
| - use an explicit argument.
| This will be an error in Scala 3.5 and later.
No warnings can be incurred under -Werror (or -Xfatal-warnings)
4 changes: 1 addition & 3 deletions tests/neg/i6716.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//> using options -Xfatal-warnings

trait Monad[T]:
def id: String
Expand All @@ -9,11 +8,10 @@ object Foo {

opaque type Bar = Foo
object Bar {
given Monad[Bar] = summon[Monad[Foo]] // warn
given Monad[Bar] = summon[Monad[Foo]] // error
}

object Test extends App {
println(summon[Monad[Foo]].id)
println(summon[Monad[Bar]].id)
}
// nopos-error: No warnings can be incurred under -Werror (or -Xfatal-warnings)
27 changes: 0 additions & 27 deletions tests/neg/i7294-a.check

This file was deleted.

14 changes: 0 additions & 14 deletions tests/neg/i7294-a.scala

This file was deleted.

12 changes: 0 additions & 12 deletions tests/neg/i7294-b.scala

This file was deleted.

25 changes: 25 additions & 0 deletions tests/neg/i7294.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- 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
|
| longer explanation available when compiling with `-explain`
10 changes: 10 additions & 0 deletions tests/neg/i7294.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

package foo

trait Foo { def g(x: Any): Any }

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

@main def Test = f
48 changes: 48 additions & 0 deletions tests/neg/looping-givens.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- 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
11 changes: 11 additions & 0 deletions tests/neg/looping-givens.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//> 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
4 changes: 2 additions & 2 deletions tests/pos-deep-subtype/CollectionStrawMan6.scala
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,11 @@ object CollectionStrawMan6 extends LowPriority {

def elemTag: ClassTag[A] = ClassTag(xs.getClass.getComponentType)

protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A](elemTag)
protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A](using elemTag)

def fromIterable[B: ClassTag](coll: Iterable[B]): Array[B] = coll.toArray[B]

protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(elemTag))
protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(using elemTag))

override def knownSize = xs.length

Expand Down
2 changes: 1 addition & 1 deletion tests/pos/extmethods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object CollectionStrawMan {

def elemTag: ClassTag[A] = ClassTag(xs.getClass.getComponentType)

protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(elemTag))
protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(using elemTag))
}
}

Expand Down
14 changes: 0 additions & 14 deletions tests/pos/given-loop-prevention.scala

This file was deleted.

2 changes: 1 addition & 1 deletion tests/pos/i17245.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type OnChannel = Channel => Any
val case1: OnChannel = Mockito.mock[OnChannel]
val case2: OnChannel = Mockito.mock
val case3 = Mockito.mock[OnChannel]
val case4: OnChannel = Mockito.mock[OnChannel](summon[ClassTag[OnChannel]])
val case4: OnChannel = Mockito.mock[OnChannel](using summon[ClassTag[OnChannel]])

// not a regressive case, but an added improvement with the fix for the above
val case5: Channel => Any = Mockito.mock[Channel => Any]
2 changes: 1 addition & 1 deletion tests/pos/i9967.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import collection.mutable

class MaxSizeMap[K, V](maxSize: Int)(using o: Ordering[K]):
val sortedMap: mutable.TreeMap[K, V] = mutable.TreeMap.empty[K, V](o)
val sortedMap: mutable.TreeMap[K, V] = mutable.TreeMap.empty[K, V](using o)

export sortedMap._
2 changes: 1 addition & 1 deletion tests/pos/t5643.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object TupledEvidenceTest {

def f[T : GetResult] = ""

f[(String,String)](getTuple[(String, String)])
f[(String,String)](using getTuple[(String, String)])

f[(String,String)]
}
4 changes: 2 additions & 2 deletions tests/run/colltest6/CollectionStrawMan6_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,11 @@ object CollectionStrawMan6 extends LowPriority {

def elemTag: ClassTag[A] = ClassTag(xs.getClass.getComponentType)

protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A](elemTag)
protected def fromIterableWithSameElemType(coll: Iterable[A]): Array[A] = coll.toArray[A](using elemTag)

def fromIterable[B: ClassTag](coll: Iterable[B]): Array[B] = coll.toArray[B]

protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(elemTag))
protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(using elemTag))

override def knownSize = xs.length

Expand Down
6 changes: 3 additions & 3 deletions tests/run/i502.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ object Test extends App {
Array[Int](1, 2)

try {
Array[Int](1, 2)(null)
Array[Int](1, 2)(using null)
???
} catch {
case _: NullPointerException => println("Ok")
}

Array[Int](1, 2)({println("foo"); summon[ClassTag[Int]]})
Array[Int](1, 2)(using {println("foo"); summon[ClassTag[Int]]})

Array[Int](1, 2)(ClassTag.apply({ println("bar"); classOf[Int]}))
Array[Int](1, 2)(using ClassTag.apply({ println("bar"); classOf[Int]}))
}
2 changes: 1 addition & 1 deletion tests/run/t2029.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Test{
val mainSet = TreeSet(1 to 5 :_*)

var compareCalled = false;
val smallerSet = TreeSet(2 to 4 :_*)(Ordering[Int].reverse)
val smallerSet = TreeSet(2 to 4 :_*)(using Ordering[Int].reverse)

println(mainSet.mkString(","))
println(smallerSet.mkString(","))
Expand Down
8 changes: 4 additions & 4 deletions tests/run/t3326.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ object Test {
def testCollectionSorted(): Unit = {
import collection.*
val order = implicitly[Ordering[Int]].reverse
var m1: SortedMap[Int, String] = SortedMap.empty[Int, String](order)
var m2: SortedMap[Int, String] = SortedMap.empty[Int, String](order)
var m1: SortedMap[Int, String] = SortedMap.empty[Int, String](using order)
var m2: SortedMap[Int, String] = SortedMap.empty[Int, String](using order)

m1 ++= List(1 -> "World")
m1 ++= List(2 -> "Hello")
Expand All @@ -49,8 +49,8 @@ object Test {
def testImmutableSorted(): Unit = {
import collection.immutable.*
val order = implicitly[Ordering[Int]].reverse
var m1: SortedMap[Int, String] = SortedMap.empty[Int, String](order)
var m2: SortedMap[Int, String] = SortedMap.empty[Int, String](order)
var m1: SortedMap[Int, String] = SortedMap.empty[Int, String](using order)
var m2: SortedMap[Int, String] = SortedMap.empty[Int, String](using order)

m1 += (1 -> "World")
m1 += (2 -> "Hello")
Expand Down
9 changes: 0 additions & 9 deletions tests/warn/context-bounds-migration.scala

This file was deleted.

2 changes: 1 addition & 1 deletion tests/warn/i15474.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

//> using options -source 3.4

import scala.language.implicitConversions

Expand Down
Loading

0 comments on commit de46c7d

Please sign in to comment.