Skip to content

Commit 4983ebb

Browse files
Deceldwijnand
authored andcommitted
Allow Tuple.Head and Tuple.Tail to accept any Tuple
1 parent cabfa68 commit 4983ebb

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ i15181.scala
2121
i15922.scala
2222
t5031_2.scala
2323
i16997.scala
24+
i17186.scala
25+
i11982a.scala
2426

2527
# Tree is huge and blows stack for printing Text
2628
i7034.scala

library/src/scala/Tuple.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ object Tuple {
8989
}
9090

9191
/** Type of the head of a tuple */
92-
type Head[X <: NonEmptyTuple] = X match {
92+
// Only bounded by `<: Tuple` not `<: NonEmptyTuple`
93+
// even though it only matches non-empty tuples.
94+
// This allows an irreducible type like `Tuple.Head[Tuple.Tail[X]]`
95+
// to avoid running into type bounds violation checks.
96+
type Head[X <: Tuple] = X match {
9397
case x *: _ => x
9498
}
9599

@@ -101,7 +105,8 @@ object Tuple {
101105
}
102106

103107
/** Type of the tail of a tuple */
104-
type Tail[X <: NonEmptyTuple] <: Tuple = X match {
108+
// See Head for why not `<: NonEmptyTuple`
109+
type Tail[X <: Tuple] <: Tuple = X match {
105110
case _ *: xs => xs
106111
}
107112

File renamed without changes.

tests/pos/i17186.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type SecondOfTwo[X <: Tuple2[Any, Any]] = Tuple.Head[Tuple.Tail[X]]
2+
val a = implicitly[SecondOfTwo[Tuple2[Int, String]] =:= String]
3+
4+
type LastOfThree[X <: Tuple3[Any, Any, Any]] = Tuple.Tail[Tuple.Tail[X]]
5+
val b = implicitly[LastOfThree[Tuple3[Int, String, Boolean]] =:= Tuple1[Boolean]]

0 commit comments

Comments
 (0)