Skip to content

Commit a581172

Browse files
committed
Add tests and fix IsMappedBy
1 parent bdd3b38 commit a581172

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

library/src/scala/Tuple.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object Tuple {
114114
* (F[A1], ..., F[An]), but not `(F[A1], B2, ..., F[An])` where B2 does not
115115
* have the shape of `F[A]`.
116116
*/
117-
type IsMappedBy[F[_]] = [X <: Tuple] =>> X <:< Map[InverseMap[X, F], F]
117+
type IsMappedBy[F[_]] = [X <: Tuple] =>> X =:= Map[InverseMap[X, F], F]
118118

119119
/** Convert an array into a tuple of unknown arity and types */
120120
def fromArray[T](xs: Array[T]): Tuple = {

tests/neg/tuple-isMappedBy-2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.Tuple.IsMappedBy
2+
3+
object Test2 {
4+
def test0[F[_], T: IsMappedBy[F]]: Unit = () // error: Type argument T does not conform to upper bound Tuple
5+
}

tests/neg/tuple-isMappedBy.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.Tuple.IsMappedBy
2+
3+
object Test1 {
4+
5+
def test[F[_], T <: Tuple: IsMappedBy[F]]: Unit = ()
6+
7+
test[List, (List[Int], Char)] // error
8+
test[List, (List[Int], Seq[Char])] // error
9+
test[Seq, (List[Int], Seq[Char])] // error
10+
test[List, Tuple] // error
11+
test[List, Nothing] // error
12+
13+
}

tests/pos/tuple-isMappedBy.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import scala.Tuple.IsMappedBy
3+
4+
object Test {
5+
6+
def test[F[_], T <: Tuple: IsMappedBy[F]]: Unit = ()
7+
8+
test[[X] =>> X, Unit]
9+
test[[X] =>> X, (Int, Long)]
10+
11+
test[List, Unit]
12+
test[List, (List[Int], List[Long])]
13+
14+
trait A[+X]
15+
trait B[-X]
16+
trait C[X]
17+
18+
test[A, Unit]
19+
test[A, (A[Int], A[Long])]
20+
21+
test[B, Unit]
22+
test[B, (B[Int], B[Long])]
23+
24+
test[C, Unit]
25+
test[C, (C[Int], C[Long])]
26+
27+
}

0 commit comments

Comments
 (0)