Skip to content

Commit de46c7d

Browse files
committed
Adapt the tests to Scala 3.5
1 parent c796bcf commit de46c7d

26 files changed

+188
-101
lines changed

library/src/scala/quoted/ToExpr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object ToExpr {
9797
/** Default implementation of `ToExpr[Array[T]]` */
9898
given ArrayToExpr[T: Type: ToExpr: ClassTag]: ToExpr[Array[T]] with {
9999
def apply(arr: Array[T])(using Quotes): Expr[Array[T]] =
100-
'{ Array[T](${Expr(arr.toSeq)}*)(${Expr(summon[ClassTag[T]])}) }
100+
'{ Array[T](${Expr(arr.toSeq)}*)(using ${Expr(summon[ClassTag[T]])}) }
101101
}
102102

103103
/** Default implementation of `ToExpr[Array[Boolean]]` */

tests/neg/given-loop-prevention.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Error: tests/neg/given-loop-prevention.scala:10:36 ------------------------------------------------------------------
2+
10 | given List[Foo] = List(summon[Foo]) // error
3+
| ^
4+
| Result of implicit search for Foo will change.
5+
| Current result Baz.given_Foo will be no longer eligible
6+
| because it is not defined before the search position.
7+
| Result with new rules: No Matching Implicit.
8+
| To opt into the new rules, compile with `-source future` or use
9+
| the `scala.language.future` language import.
10+
|
11+
| To fix the problem without the language import, you could try one of the following:
12+
| - use a `given ... with` clause as the enclosing given,
13+
| - rearrange definitions so that Baz.given_Foo comes earlier,
14+
| - use an explicit argument.

tests/neg/given-loop-prevention.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
class Foo
3+
4+
object Bar {
5+
given Foo with {}
6+
given List[Foo] = List(summon[Foo]) // ok
7+
}
8+
9+
object Baz {
10+
given List[Foo] = List(summon[Foo]) // error
11+
given Foo with {}
12+
}

tests/neg/i6716.check

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
-- Warning: tests/neg/i6716.scala:12:39 --------------------------------------------------------------------------------
2-
12 | given Monad[Bar] = summon[Monad[Foo]] // warn
1+
-- Error: tests/neg/i6716.scala:11:39 ----------------------------------------------------------------------------------
2+
11 | given Monad[Bar] = summon[Monad[Foo]] // error
33
| ^
44
| Result of implicit search for Monad[Foo] will change.
55
| Current result Bar.given_Monad_Bar will be no longer eligible
@@ -12,5 +12,3 @@
1212
| - use a `given ... with` clause as the enclosing given,
1313
| - rearrange definitions so that Bar.given_Monad_Bar comes earlier,
1414
| - use an explicit argument.
15-
| This will be an error in Scala 3.5 and later.
16-
No warnings can be incurred under -Werror (or -Xfatal-warnings)

tests/neg/i6716.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//> using options -Xfatal-warnings
21

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

109
opaque type Bar = Foo
1110
object Bar {
12-
given Monad[Bar] = summon[Monad[Foo]] // warn
11+
given Monad[Bar] = summon[Monad[Foo]] // error
1312
}
1413

1514
object Test extends App {
1615
println(summon[Monad[Foo]].id)
1716
println(summon[Monad[Bar]].id)
1817
}
19-
// nopos-error: No warnings can be incurred under -Werror (or -Xfatal-warnings)

tests/neg/i7294-a.check

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/neg/i7294-a.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/neg/i7294-b.scala

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/neg/i7294.check

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Error: tests/neg/i7294.scala:7:10 -----------------------------------------------------------------------------------
2+
7 | case x: T => x.g(10) // error // error
3+
| ^
4+
| Result of implicit search for scala.reflect.TypeTest[Nothing, T] will change.
5+
| Current result foo.f will be no longer eligible
6+
| because it is not defined before the search position.
7+
| Result with new rules: No Matching Implicit.
8+
| To opt into the new rules, compile with `-source future` or use
9+
| the `scala.language.future` language import.
10+
|
11+
| To fix the problem without the language import, you could try one of the following:
12+
| - use a `given ... with` clause as the enclosing given,
13+
| - rearrange definitions so that foo.f comes earlier,
14+
| - use an explicit argument.
15+
|
16+
| where: T is a type in given instance f with bounds <: foo.Foo
17+
-- [E007] Type Mismatch Error: tests/neg/i7294.scala:7:18 --------------------------------------------------------------
18+
7 | case x: T => x.g(10) // error // error
19+
| ^^^^^^^
20+
| Found: Any
21+
| Required: T
22+
|
23+
| where: T is a type in given instance f with bounds <: foo.Foo
24+
|
25+
| longer explanation available when compiling with `-explain`

tests/neg/i7294.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
package foo
3+
4+
trait Foo { def g(x: Any): Any }
5+
6+
inline given f[T <: Foo]: T = ??? match {
7+
case x: T => x.g(10) // error // error
8+
}
9+
10+
@main def Test = f

tests/neg/looping-givens.check

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- Error: tests/neg/looping-givens.scala:9:22 --------------------------------------------------------------------------
2+
9 | given aa: A = summon // error
3+
| ^
4+
| Result of implicit search for T will change.
5+
| Current result ab will be no longer eligible
6+
| because it is not defined before the search position.
7+
| Result with new rules: a.
8+
| To opt into the new rules, compile with `-source future` or use
9+
| the `scala.language.future` language import.
10+
|
11+
| To fix the problem without the language import, you could try one of the following:
12+
| - use a `given ... with` clause as the enclosing given,
13+
| - rearrange definitions so that ab comes earlier,
14+
| - use an explicit argument.
15+
|
16+
| where: T is a type variable with constraint <: A
17+
-- Error: tests/neg/looping-givens.scala:10:22 -------------------------------------------------------------------------
18+
10 | given bb: B = summon // error
19+
| ^
20+
| Result of implicit search for T will change.
21+
| Current result ab will be no longer eligible
22+
| because it is not defined before the search position.
23+
| Result with new rules: b.
24+
| To opt into the new rules, compile with `-source future` or use
25+
| the `scala.language.future` language import.
26+
|
27+
| To fix the problem without the language import, you could try one of the following:
28+
| - use a `given ... with` clause as the enclosing given,
29+
| - rearrange definitions so that ab comes earlier,
30+
| - use an explicit argument.
31+
|
32+
| where: T is a type variable with constraint <: B
33+
-- Error: tests/neg/looping-givens.scala:11:28 -------------------------------------------------------------------------
34+
11 | given ab: (A & B) = summon // error
35+
| ^
36+
| Result of implicit search for T will change.
37+
| Current result ab will be no longer eligible
38+
| because it is not defined before the search position.
39+
| Result with new rules: Search Failure: joint(ab, ab).
40+
| To opt into the new rules, compile with `-source future` or use
41+
| the `scala.language.future` language import.
42+
|
43+
| To fix the problem without the language import, you could try one of the following:
44+
| - use a `given ... with` clause as the enclosing given,
45+
| - rearrange definitions so that ab comes earlier,
46+
| - use an explicit argument.
47+
|
48+
| where: T is a type variable with constraint <: A & B

tests/neg/looping-givens.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//> options -source 3.4
2+
3+
class A
4+
class B
5+
6+
given joint(using a: A, b: B): (A & B) = ???
7+
8+
def foo(using a: A, b: B) =
9+
given aa: A = summon // error
10+
given bb: B = summon // error
11+
given ab: (A & B) = summon // error

tests/pos-deep-subtype/CollectionStrawMan6.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,11 @@ object CollectionStrawMan6 extends LowPriority {
754754

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

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

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

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

763763
override def knownSize = xs.length
764764

tests/pos/extmethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object CollectionStrawMan {
1717

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

20-
protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(elemTag))
20+
protected[this] def newBuilder = new ArrayBuffer[A].mapResult(_.toArray(using elemTag))
2121
}
2222
}
2323

tests/pos/given-loop-prevention.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/pos/i17245.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type OnChannel = Channel => Any
1414
val case1: OnChannel = Mockito.mock[OnChannel]
1515
val case2: OnChannel = Mockito.mock
1616
val case3 = Mockito.mock[OnChannel]
17-
val case4: OnChannel = Mockito.mock[OnChannel](summon[ClassTag[OnChannel]])
17+
val case4: OnChannel = Mockito.mock[OnChannel](using summon[ClassTag[OnChannel]])
1818

1919
// not a regressive case, but an added improvement with the fix for the above
2020
val case5: Channel => Any = Mockito.mock[Channel => Any]

tests/pos/i9967.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import collection.mutable
22

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

66
export sortedMap._

tests/pos/t5643.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object TupledEvidenceTest {
1313

1414
def f[T : GetResult] = ""
1515

16-
f[(String,String)](getTuple[(String, String)])
16+
f[(String,String)](using getTuple[(String, String)])
1717

1818
f[(String,String)]
1919
}

tests/run/colltest6/CollectionStrawMan6_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,11 @@ object CollectionStrawMan6 extends LowPriority {
755755

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

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

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

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

764764
override def knownSize = xs.length
765765

tests/run/i502.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ object Test extends App {
66
Array[Int](1, 2)
77

88
try {
9-
Array[Int](1, 2)(null)
9+
Array[Int](1, 2)(using null)
1010
???
1111
} catch {
1212
case _: NullPointerException => println("Ok")
1313
}
1414

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

17-
Array[Int](1, 2)(ClassTag.apply({ println("bar"); classOf[Int]}))
17+
Array[Int](1, 2)(using ClassTag.apply({ println("bar"); classOf[Int]}))
1818
}

tests/run/t2029.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test{
55
val mainSet = TreeSet(1 to 5 :_*)
66

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

1010
println(mainSet.mkString(","))
1111
println(smallerSet.mkString(","))

tests/run/t3326.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ object Test {
2828
def testCollectionSorted(): Unit = {
2929
import collection.*
3030
val order = implicitly[Ordering[Int]].reverse
31-
var m1: SortedMap[Int, String] = SortedMap.empty[Int, String](order)
32-
var m2: SortedMap[Int, String] = SortedMap.empty[Int, String](order)
31+
var m1: SortedMap[Int, String] = SortedMap.empty[Int, String](using order)
32+
var m2: SortedMap[Int, String] = SortedMap.empty[Int, String](using order)
3333

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

5555
m1 += (1 -> "World")
5656
m1 += (2 -> "Hello")

tests/warn/context-bounds-migration.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/warn/i15474.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
//> using options -source 3.4
22

33
import scala.language.implicitConversions
44

0 commit comments

Comments
 (0)