This page is no longer maintained — Please continue to the home page at

Implicit method not considered if the method for which the type would have been converted has a type parameter and a not applicable method with the same exists ...

No replies
Simon Ochsenreither
Joined: 2011-07-17,
User offline. Last seen 42 years 45 weeks ago.
... is this a compiler bug or as specified?

This question arose from the following SO question:

Kipton Barros was able to minimize it and I'll just quote him because he explains it much better than me:

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? 


It works if I do one or both of the following:
 - I choose another method name, like **
 - I remove the type parameter

Both things are not really an option to me, so if someone has an idea for a workaround or identifies this as a bug, I would be very grateful!



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland