The setup for this example (Scala 2.10.3):
trait S[A] trait T[A] implicit class X[A : S](a: A) { def foo() { } } implicit class Y[A : T](a: A) { def foo() { } } implicit object I extends S[String]
This compiles:
new X("").foo()
It does not mean:
new Y("").foo()
because there is no implicit T[String] .
could not find implicit value for evidence parameter of type T[String] new Y("").foo() ^
Therefore, I would suggest that scalac can uniquely apply an implicit conversion from String to X :
"".foo()
But instead we get:
type mismatch; found : String("") required: ?{def foo: ?} Note that implicit conversions are not applicable because they are ambiguous: both method X of type [A](a: A)(implicit evidence$1: S[A])X[A] and method Y of type [A](a: A)(implicit evidence$1: T[A])Y[A] are possible conversion functions from String("") to ?{def foo: ?} "".foo() ^
Is it intentional? Is the skalak not suggesting whether each transformation will really work when it lists candidates?
source share