diff --git a/library/src/scala/Tuple.scala b/library/src/scala/Tuple.scala index 418c58fdd040..c6db4d0b83bc 100644 --- a/library/src/scala/Tuple.scala +++ b/library/src/scala/Tuple.scala @@ -109,18 +109,18 @@ object Tuple { } /** Fold a tuple `(T1, ..., Tn)` into `F[T1, F[... F[Tn, Z]...]]]` */ - type Fold[T <: Tuple, Z, F[_, _]] = T match + type Fold[Tup <: Tuple, Z, F[_, _]] = Tup match case EmptyTuple => Z case h *: t => F[h, Fold[t, Z, F]] /** Converts a tuple `(T1, ..., Tn)` to `(F[T1], ..., F[Tn])` */ - type Map[Tup <: Tuple, F[_]] <: Tuple = Tup match { + type Map[Tup <: Tuple, F[_ <: Union[Tup]]] <: Tuple = Tup match { case EmptyTuple => EmptyTuple case h *: t => F[h] *: Map[t, F] } /** Converts a tuple `(T1, ..., Tn)` to a flattened `(..F[T1], ..., ..F[Tn])` */ - type FlatMap[Tup <: Tuple, F[_] <: Tuple] <: Tuple = Tup match { + type FlatMap[Tup <: Tuple, F[_ <: Union[Tup]] <: Tuple] <: Tuple = Tup match { case EmptyTuple => EmptyTuple case h *: t => Concat[F[h], FlatMap[t, F]] } diff --git a/tests/pos/i12645.scala b/tests/pos/i12645.scala new file mode 100644 index 000000000000..ff7e333ec267 --- /dev/null +++ b/tests/pos/i12645.scala @@ -0,0 +1,11 @@ +case class TBox[A <: Tuple](v: A) +case class IBox[A <: Int](v: A) + +@main def m = + val t: TBox[EmptyTuple] = TBox(EmptyTuple) + val tt: Tuple.Map[(EmptyTuple, EmptyTuple), TBox] = (TBox(EmptyTuple), TBox(EmptyTuple)) + + val tt2: Tuple.Map[(1, 2), IBox] = (IBox(1), IBox(2)) + + type F[X] = (X, X) + val tt3: Tuple.FlatMap[(1, 2), F] = (1, 1, 2, 2)