Skip to content

Commit 6011d24

Browse files
committed
gadt: Add the contravariant test case variant
1 parent a2f24e8 commit 6011d24

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/neg/i14983.contra.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sealed trait Show[-A]
2+
final case class Pure[-B](showB: B => String) extends Show[B]
3+
final case class Many[-C](showL: List[C] => String) extends Show[List[C]]
4+
5+
object Test:
6+
def meth[X](show: Show[X]): X => String = show match
7+
case Pure(showB) => showB
8+
case Many(showL) =>
9+
val res = (xs: List[String]) => xs.head.length.toString
10+
res // error: Found: List[String] => String Required: X => String where: X is a type in method meth with bounds <: List[C$1]
11+
12+
def main(args: Array[String]): Unit =
13+
val show = Many((is: List[Int]) => (is.head + 1).toString)
14+
val fn = meth(show)
15+
assert(fn(List(42)) == "43") // was: ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String

0 commit comments

Comments
 (0)