softwaremill / scala-clippy

Good advice for Scala compiler errors
Apache License 2.0
312 stars 20 forks source link

Clippy is dropping "Implicit conversions ambiugity" advice from scalac without adequate replacement #48

Closed vladap closed 7 years ago

vladap commented 7 years ago

I have created a simple hierarchy with implicit coversions to achieve diamond during implicit resolution. Scalac fails compilation with the following advice:

Note that implicit conversions are not applicable because they are ambiguous: [error] both method toMessage in object B of type (b: fiddles.implicits.ImplicitResolutionDiamond.B)Array[String] [error] and method toMessage in object A of type (a: fiddles.implicits.ImplicitResolutionDiamond.A)Array[String] [error] are possible conversion functions from fiddles.implicits.ImplicitResolutionDiamond.C to Array[String]

When I add Clippy sbt plugin and set clippyColorsEnabled := true this information is lost and I get only this one instead:

Clippy advises, pay attention to the marked parts: [error] found : fiddles.implicits.ImplicitResolutionDiamond.C [error] required: Array[String]

The test code. CAUTION: Don't use such invisible implicit conversions in real code. They are designed as quick example to fail implicit search during compilation due to ambiguity:

object ImplicitResolutionDiamond {

  trait A
  object A {
    implicit def toMessage(a: A): Array[String] = {
      println("Implicit conversion A -> Array[String]")
      Array("A", "Hello World")
    }
  }

  trait B
  object B {
    implicit def toMessage(b: B): Array[String] = {
      println("Implicit conversion B -> Array[String]")
      Array("B", "Hello World")
    }
  }

  // Companion objects of all C supertypes will be searched for implicits.
  class C extends A with B

  def show(message: Array[String]): Unit = {
    println(s"Shown: ${message.mkString(",")}")
  }

  def run(): Unit = {
    val c = new C
    println("Called show with C, show requires Array[String] which triggers implicit conversion")
    show(c)
  }

}
adamw commented 7 years ago

Thanks for the report! can you check 0.5.2?

the error parser didn't foresee that there might be some additional notes :)

vladap commented 7 years ago

It works now. Thank you for the quick fix.