|
| 1 | +import language.`3.0-migration` |
| 2 | +import scala.language.implicitConversions |
| 3 | + |
| 4 | +object Test1 { |
| 5 | + implicit def implicitLength(s: String): Int = s.length |
| 6 | + val length: Int = "qwerty" // ok |
| 7 | +} |
| 8 | + |
| 9 | +object Test2 { |
| 10 | + implicit val implicitLength: Conversion[String, Int] = _.length |
| 11 | + val length: Int = "qwerty" // ok |
| 12 | +} |
| 13 | + |
| 14 | +object Test3 { |
| 15 | + implicit val implicitLength: String => Int = _.length |
| 16 | + val length: Int = "qwerty" // error |
| 17 | +} |
| 18 | + |
| 19 | +object Test4 { |
| 20 | + implicit def implicitLength: String => Int = _.length |
| 21 | + val length: Int = "qwerty" // error |
| 22 | +} |
| 23 | + |
| 24 | +object Test5 { |
| 25 | + implicit def implicitLength[A]: String => Int = _.length |
| 26 | + val length: Int = "qwerty" // error |
| 27 | +} |
| 28 | + |
| 29 | +object Test6 { |
| 30 | + implicit val implicitLength: Map[String, Int] = Map("qwerty" -> 6) |
| 31 | + val length: Int = "qwerty" // error |
| 32 | +} |
| 33 | + |
| 34 | +object Test7 { |
| 35 | + implicit def a2int[A](a: A)(implicit ev: A => Int): Int = a // error |
| 36 | +} |
| 37 | + |
| 38 | +object Test8 { |
| 39 | + implicit def a2int[A](a: A)(implicit ev: A => Int): Int = ev(a) // ok |
| 40 | +} |
| 41 | + |
| 42 | +object Test9 { |
| 43 | + implicit def a2int[A](a: A)(implicit ev: A <:< Int): Int = a // ok |
| 44 | +} |
| 45 | + |
| 46 | +object Test10 { |
| 47 | + trait Foo { |
| 48 | + def foo = "foo" |
| 49 | + } |
| 50 | + implicit def a2foo[A](a: A): Foo = new Foo {} |
| 51 | + 123.foo // ok |
| 52 | +} |
| 53 | + |
| 54 | +object Test11 { |
| 55 | + trait Foo { |
| 56 | + def foo = "foo" |
| 57 | + } |
| 58 | + implicit def a2foo[A]: A => Foo = _ => new Foo {} |
| 59 | + 123.foo // error |
| 60 | +} |
| 61 | + |
| 62 | +object Test12 { |
| 63 | + implicit class FooOps(a: Any) { |
| 64 | + def foo = "foo" |
| 65 | + } |
| 66 | + 123.foo // ok |
| 67 | +} |
| 68 | + |
| 69 | +object Test13 { |
| 70 | + def foo()(implicit x: String => Int) = ??? |
| 71 | + implicit val f: String => Int = _.size |
| 72 | + foo() // ok |
| 73 | +} |
| 74 | + |
| 75 | +object Test14 { |
| 76 | + case class MySeq[A](underlying: Seq[A]) |
| 77 | + |
| 78 | + implicit def mySeq2seq[A](mySeq: MySeq[A]): Seq[A] = mySeq.underlying |
| 79 | + val s: Seq[Int] = MySeq(Seq(1, 2, 3)) // ok |
| 80 | +} |
| 81 | + |
| 82 | +object Test15 { |
| 83 | + implicit def implicitSeq[A]: Seq[A] = ??? |
| 84 | + def foo(implicit ev: Seq[Int]): Unit = ??? |
| 85 | + foo |
| 86 | +} |
0 commit comments