fork download
  1. import language.implicitConversions
  2.  
  3. object Test extends App {
  4.  
  5. trait JValue
  6. case class JInt(x: Int) extends JValue
  7. case class JString(x: String) extends JValue
  8. implicit def intToJInt(x: Int) = JInt(x)
  9. implicit def stringToJString(x: String) = JString(x)
  10.  
  11. implicit class pimp[A <: JValue](xs: List[A]) {
  12. def |:[B >: A <: JValue] (x: B): List[B] = x :: xs
  13. }
  14.  
  15. val foo = 42 |: "hello" |: Nil
  16.  
  17. println(foo)
  18.  
  19. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.scala:15: error: inferred type arguments [Object] do not conform to method |:'s type parameter bounds [B >: A <: Test.JValue]
  val foo = 42 |: "hello" |: Nil
                          ^
one error found
spoj: The program compiled successfully, but Main.class was not found.
      Class Main should contain method: def main(args: Array[String]).
stdout
Standard output is empty