Consider the following code, derived from the metascala project:
object Units {
case class Quantity[M <: MInt, T: Numeric](value: T) {
type This = Q
To get things started, here's a stand-alone example that gives the same problem,
object Units {
case class Quantity[T: Numeric](value: T) {
def *[M](m: Quantity[T]) = // type M can't be inferred below
Quantity[T](implicitly[Numeric[T]].times(value, m.value))
}
implicit def measure[T: Numeric](v: T) = Quantity[T](v)
val length0 = measure(5) * Quantity(5) // works
val length1 = 5 * Quantity(5) // doesn't work
}
For some reason, the conversion measure
isn't being found because of the type parameter M
on the method *
. If the type parameter is removed from *
, things compile fine. Maybe someone else can explain why?
Edit. This is looking like a limitation of the Scala compiler, since renaming *
to something like ***
resolves the problem. Perhaps the existence of Int.*
(without a type parameter) is precluding the implicit conversion for use of Quantity.*[M]
(with a type parameter). This reminds me of the requirement that overridden methods must have the same exact type parameters.