Not bad, but I would definitely not call it a mistake.
It comes down to
class A class B implicit def aToB(a: A) : B = a
There is no need for both sides of the transformation to be connected in any way. Implicit is the same as writing
implicit def aToB(a: A): B = aToB(a)
because the compiler inserts a call to aToB
to convert the result of a
to the desired return type B
The goto 0
implementation is just tail call optimization. Perhaps the compiler generates a warning when it generates a method that starts in this way.
Maybe, it may be the rule that implicit methods are not available as implicit within your own body. But it does not always create an endless loop
implicit def listAToListB(l: list[A] = l match { case Nil => Nil case x:xs => toB(x) :: xs // equivalent to toB(x) :: listAToList[B](xs) }
(ok is just a map(toB)
). In any case, the same thing can happen with two mutually recursive implications. In my opinion, you should not configure the specification in order to avoid the possibility of writing an endless chain of "do nothing", among many others. But a warning when such a cycle is detected, regardless of implications, will be pleasant.
Didier dupont
source share