Closed Dveim closed 1 year ago
As I understand it, point 1 is intentional (though arguably unfortunate). Scala 3 clamps down, as per https://docs.scala-lang.org/scala3/guides/migration/incompat-contextual-abstractions.html :
Scala 3 does not support implicit conversion from an implicit function value, of the form implicit val ev: A => B
Not sure about point 2, but at this point, it seems unlikely we'd mess with it.
The Scaladoc is wrong when it says that the warning "governs" vals, implying vals typed as Function1 but not other vals.
The confusing part is that other types may be function types:
class C {
implicit val cv0: List[String] = List("zero", "one", "two", "three")
//implicit val cv1: Int => String = _.toString
implicit def cv2(i: Int): String = i.toString * 2
def f(i: Int): String = i
}
object Test extends App {
val c = new C
println {
c.f(3)
}
}
Given
implicit val val_int2str = (i: Int) => {println("val");i.toString}
andimplicit def def_int2str(i: Int) = {println("def");i.toString}
, 1) there is no warning about "please enable implicits explicitly" forval
2)val
always has precedence overdef
, no collision happens