Skip to content

Commit

Permalink
Allow Tuple.Head and Tuple.Tail to accept any Tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Decel authored and nicolasstucki committed Dec 5, 2023
1 parent a3854cb commit 8cffc7d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ i9804.scala
i13433.scala
i16649-irrefutable.scala
strict-pattern-bindings-3.0-migration.scala
i17186b.scala
i11982a.scala

# Tree is huge and blows stack for printing Text
i7034.scala
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/Tuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object Tuple {
}

/** Type of the head of a tuple */
type Head[X <: NonEmptyTuple] = X match {
type Head[X <: Tuple] = X match {
case x *: _ => x
}

Expand All @@ -108,7 +108,7 @@ object Tuple {
}

/** Type of the tail of a tuple */
type Tail[X <: NonEmptyTuple] <: Tuple = X match {
type Tail[X <: Tuple] <: Tuple = X match {
case _ *: xs => xs
}

Expand Down
6 changes: 3 additions & 3 deletions tests/neg/i11982a.scala → tests/pos/i11982a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ object Unpair {

def unpair[X <: Tuple2[?, ?]](
using a: ValueOf[Tuple.Head[X]],
b: ValueOf[Tuple.Head[Tuple.Tail[X]]] // error
): Tuple2[Tuple.Head[X], Tuple.Head[Tuple.Tail[X]]] = // error
b: ValueOf[Tuple.Head[Tuple.Tail[X]]]
): Tuple2[Tuple.Head[X], Tuple.Head[Tuple.Tail[X]]] =
type AA = Tuple.Head[X]
type BB = Tuple.Head[Tuple.Tail[X]] // error
type BB = Tuple.Head[Tuple.Tail[X]]
pair[AA, BB](using a, b)
}
5 changes: 5 additions & 0 deletions tests/pos/i17186a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type second[X <: Tuple2[Any, Any]] = Tuple.Head[Tuple.Tail[X]]
type middle[X <: Tuple3[Any, Any, Any]] = Tuple.Head[Tuple.Tail[X]]

val a: Tuple.Head[Tuple.Tail[Tuple2[Int, String]]] = ???
val b: Tuple.Head[Tuple.Tail[Tuple3[Int, String, Boolean]]] = ???
5 changes: 5 additions & 0 deletions tests/pos/i17186b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type SecondOfTwo[X <: Tuple2[Any, Any]] = Tuple.Head[Tuple.Tail[X]]
val a = implicitly[SecondOfTwo[Tuple2[Int, String]] =:= String]

type LastOfThree[X <: Tuple3[Any, Any, Any]] = Tuple.Tail[Tuple.Tail[X]]
val b = implicitly[LastOfThree[Tuple3[Int, String, Boolean]] =:= Tuple1[Boolean]]

0 comments on commit 8cffc7d

Please sign in to comment.