Skip to content

Commit c65503d

Browse files
author
Aleksander Boruch-Gruszecki
committed
Add more GADT tests
1 parent 8f2e6e1 commit c65503d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

tests/gadt-neg/injectivity.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object injectivity {
2+
sealed trait EQ[A, B]
3+
final case class Refl[A](u: Unit) extends EQ[A, A]
4+
5+
def conform[A, B, C, D](a: A, b: B, eq: EQ[(A, B), (C, D)]): C =
6+
eq match {
7+
case _: Refl[a] =>
8+
val ab: (A, B) = (a, b)
9+
val cd: (C, D) = ab
10+
val bb: (B, B) = ab // error
11+
val cc: (C, C) = cd // error
12+
val dd: (D, D) = cd // error
13+
val rab: a = ab
14+
val rcd: a = cd
15+
a
16+
}
17+
}

tests/gadt/injectivity.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
object injectivity {
22
sealed trait EQ[A, B]
3-
final case class Refl[A](u: Unit) extends EQ[A, A]
3+
final case class Refl[A]() extends EQ[A, A]
44

55
def conform[A, B, C, D](a: A, b: B, eq: EQ[(A, B), (C, D)]): C =
66
eq match {
7-
case Refl(()) => a
7+
case _: Refl[a] =>
8+
val ab: (A, B) = (a, b)
9+
val cd: (C, D) = ab
10+
val rab: a = ab
11+
val rcd: a = cd
12+
a
813
}
914
}

0 commit comments

Comments
 (0)