Skip to content

Commit

Permalink
Backport "Refine the bounds of the Tuple.Filter type lambda predica…
Browse files Browse the repository at this point in the history
…te .." to 3.6 (#21960)

Backports #21286 to the 3.6.2.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Nov 18, 2024
2 parents 8ceb324 + 2e5cec9 commit 650efea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ object Tuple {
* ```
* @syntax markdown
*/
type Filter[Tup <: Tuple, P[_] <: Boolean] <: Tuple = Tup match {
type Filter[Tup <: Tuple, P[_ <: Union[Tup]] <: Boolean] <: Tuple = Tup match {
case EmptyTuple => EmptyTuple
case h *: t => P[h] match {
case true => h *: Filter[t, P]
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/tuple-filter-compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

type OldFilter[Tup <: Tuple, P[_] <: Boolean] = Nothing
type NewFilter[Tup <: Tuple, P[_ <: Tuple.Union[Tup]] <: Boolean] = Nothing

trait A:
type X >: OldFilter <: OldFilter

trait B1 extends A:
type X = OldFilter // ok

trait B2 extends A:
type X = NewFilter // error: breaking change
6 changes: 6 additions & 0 deletions tests/pos/tuple-filter.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import scala.compiletime.ops.int.<

type P[x] <: Boolean = x match {
case 3 => false
case _ => true
}

type RejectAll[x] = false

type Pos[X <: Int] = 0 < X

def Test =
summon[Tuple.Filter[(1, 2, 3, 4), P] =:= (1, 2, 4)]
summon[Tuple.Filter[(1, 2, 3, 4), RejectAll] =:= EmptyTuple]
summon[Tuple.Filter[EmptyTuple, P] =:= EmptyTuple]
summon[Tuple.Filter[(1, -2, 3, -4), Pos] =:= (1, 3)]

0 comments on commit 650efea

Please sign in to comment.