-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine the bounds of the
Tuple.Filter
type lambda predicate ..
to only require it be defined on the elements of the tuple. This is one of the ongoing proposed tuple improvements, addressing #19175. As carefully pointed out by @sjrd, this _is_ a potential breaking change. See tests/neg/tuple-filter-compat.scala for an example. This is not an unprecedented change however, the analogous improvements were made to `Tuple.{Map, FlatMap}` in 28a695e.
- Loading branch information
1 parent
7f141a9
commit 034207b
Showing
3 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |