Why can't the scala compiler find an implicit parameter value / conversion when it is overloaded and has a generic param type?

Scala 2.8.1

Take the following class hierarchy

abstract class A class B extends A class C extends A 

Why the scala compiler cannot find the implicit parameter for send when sending instance B below

 implicit def routingKeyFor[T <: A](value: T) = value.getClass.getSimpleName implicit def routingKeyFor(value: C) = "custom C" def send[T <: A](value: T)(implicit createRoutingKey: T => String): Validation[Throwable, String] = Success(createRoutingKey(value)) val resultOfSendingB = send(new B) val resultOfSendingC = send(new C) 

Why can the compiler find the value for the implicit parameter when renaming the general version of routingKeyFor ?

 implicit def someOtherName[T <: A](value: T) = value.getClass.getSimpleName 
+4
source share
1 answer

The second implicit is the shading of the first. Why someone guesses, and you can open a problem for him (after checking that it has not been reported before), but this can be only one of those things that throw a wrench into the type inference work.

+3
source

Source: https://habr.com/ru/post/1379712/


All Articles