Skip to content

Commit 650efea

Browse files
Backport "Refine the bounds of the Tuple.Filter type lambda predicate .." to 3.6 (#21960)
Backports #21286 to the 3.6.2. PR submitted by the release tooling. [skip ci]
2 parents 8ceb324 + 2e5cec9 commit 650efea

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Diff for: library/src/scala/Tuple.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ object Tuple {
166166
* ```
167167
* @syntax markdown
168168
*/
169-
type Filter[Tup <: Tuple, P[_] <: Boolean] <: Tuple = Tup match {
169+
type Filter[Tup <: Tuple, P[_ <: Union[Tup]] <: Boolean] <: Tuple = Tup match {
170170
case EmptyTuple => EmptyTuple
171171
case h *: t => P[h] match {
172172
case true => h *: Filter[t, P]

Diff for: tests/neg/tuple-filter-compat.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
type OldFilter[Tup <: Tuple, P[_] <: Boolean] = Nothing
3+
type NewFilter[Tup <: Tuple, P[_ <: Tuple.Union[Tup]] <: Boolean] = Nothing
4+
5+
trait A:
6+
type X >: OldFilter <: OldFilter
7+
8+
trait B1 extends A:
9+
type X = OldFilter // ok
10+
11+
trait B2 extends A:
12+
type X = NewFilter // error: breaking change

Diff for: tests/pos/tuple-filter.scala

+6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
import scala.compiletime.ops.int.<
2+
13
type P[x] <: Boolean = x match {
24
case 3 => false
35
case _ => true
46
}
7+
58
type RejectAll[x] = false
69

10+
type Pos[X <: Int] = 0 < X
11+
712
def Test =
813
summon[Tuple.Filter[(1, 2, 3, 4), P] =:= (1, 2, 4)]
914
summon[Tuple.Filter[(1, 2, 3, 4), RejectAll] =:= EmptyTuple]
1015
summon[Tuple.Filter[EmptyTuple, P] =:= EmptyTuple]
16+
summon[Tuple.Filter[(1, -2, 3, -4), Pos] =:= (1, 3)]

0 commit comments

Comments
 (0)