I believe that I can answer what is happening here. This is due to other implicit conversions and what you just created. If you add this trace, you can confirm that the stack overflow usually refers to - a function that calls itself repeatedly until the java stack space falls:
implicit val stringsToDouble: String => Double= { x=>println("called inner "+x); x.toDouble }
.... internal 4.5 internal 4.5 internal 4.5 internal 4.5 internal 4.5ERROR: java.lang.StackOverflowError
I think this happens - toDouble is not a natural function of the java string, but rather happens using an implicit conversion to StringOps (or StringLike, I'm not sure, but this is the same problem).
So, when you call toDouble, the compiler starts looking for an implicit conversion that may contain the "toDouble" function. Theoretically, this could be any resulting class.
BUT - what should happen if it can do several implicit conversions? Unfortunately, "Double" also contains the toDouble function, as proven here:
val x = 44.4 x.toDouble
And guess what? This means that your new implicit function, the one closest in scope, wins the competition and gets a call in the circle to execute "toDouble" - effectively trying to turn the string into a double to repeatedly call toDouble (in the Double class). I admit this is rather confusing, but the proof is right.
Here's the fix .. it comes up with an explanation and prevents recursive calls.
implicit val stringsToDouble: String => Double= { java.lang.Double.parseDouble(_) }
source share