File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments