Skip to content

Commit 43d74c8

Browse files
Combine cases of Tuple.Zip disjoint from (h1 *: t1, h2 *: t2) (#21287)
If we reach the second case of `Zip[T1 <: Tuple, T2 <: Tuple]`, then we know `(T1, T2)` is disjoint from `(NonEmptyTuple, NonEmptyTuple)`, from which we can conclude at least one of the two is an `EmptyTuple`. Addressing #19175
2 parents 6a7d5d3 + 14bf406 commit 43d74c8

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

library/src/scala/Tuple.scala

+3-6
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,12 @@ object Tuple {
205205
}
206206

207207
/** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt`
208-
* where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`,
209-
* returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct`
210-
* where `Ct` is `EmptyTuple` if `At` or `Bt` is `EmptyTuple`, otherwise `Ct` is `Tuple`.
208+
* where at least one of `At` or `Bt` is `EmptyTuple`,
209+
* returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: EmptyTuple`.
211210
*/
212211
type Zip[T1 <: Tuple, T2 <: Tuple] <: Tuple = (T1, T2) match {
213212
case (h1 *: t1, h2 *: t2) => (h1, h2) *: Zip[t1, t2]
214-
case (EmptyTuple, _) => EmptyTuple
215-
case (_, EmptyTuple) => EmptyTuple
216-
case _ => Tuple
213+
case _ => EmptyTuple
217214
}
218215

219216
/** Converts a tuple `(F[T1], ..., F[Tn])` to `(T1, ... Tn)` */

tests/pos/tuple-zip.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
import scala.Tuple.Zip
3+
4+
type A
5+
type B
6+
type C
7+
8+
def Test =
9+
10+
summon[Zip[A *: B *: C *: EmptyTuple, C *: B *: A *: EmptyTuple] =:= (A, C) *: (B, B) *: (C, A) *: EmptyTuple]
11+
12+
summon[Zip[A *: B *: EmptyTuple, C *: B *: A *: EmptyTuple] =:= (A, C) *: (B, B) *: EmptyTuple]
13+
summon[Zip[A *: B *: C *: EmptyTuple, C *: B *: EmptyTuple] =:= (A, C) *: (B, B) *: EmptyTuple]
14+
15+
summon[Zip[A *: B *: C *: Tuple, C *: B *: A *: Tuple] =:= (A, C) *: (B, B) *: (C, A) *: Zip[Tuple, Tuple]]
16+
summon[Zip[A *: B *: C *: Tuple, C *: B *: A *: Tuple] <:< (A, C) *: (B, B) *: (C, A) *: Tuple]
17+
18+
summon[Zip[A *: B *: Tuple, C *: B *: A *: Tuple] =:= (A, C) *: (B, B) *: Zip[Tuple, A *: Tuple]]
19+
summon[Zip[A *: B *: NonEmptyTuple, C *: B *: A *: Tuple] =:= (A, C) *: (B, B) *: Zip[NonEmptyTuple, A *: Tuple]]
20+
summon[Zip[A *: B *: EmptyTuple, C *: B *: A *: Tuple] =:= (A, C) *: (B, B) *: EmptyTuple]

0 commit comments

Comments
 (0)