5

Here's some code that compiles in 2.11, but fails in 2.12:

object Main extends App {
  implicit val c: Configured[String] = new Configured[String] { def apply(v: CfgValue): Option[String] = None }
  val a = Configured[String]
}

sealed trait CfgValue {
  def convertTo[A:Configured]: Option[A] = implicitly[Configured[A]].apply(this)
}
trait Configured[A] {
  def apply(v: CfgValue): Option[A]
}

object Configured {
  def apply[A:Configured]: Configured[A] = implicitly[Configured[A]]

  def apply[A](f: CfgValue => Option[A]): Configured[A] = new Configured[A] {
    def apply(v: CfgValue) = f(v)
  }
}

Fails in 2.12 with:

[error] /tmp/rendererKzypu6fJSu/src/main/scala/test.scala:7: ambiguous reference to overloaded definition,
[error] both method apply in object Configured of type (f: CfgValue => Option[String])Configured[String]
[error] and  method apply in object Configured of type (implicit evidence$2: Configured[String])Configured[String]
[error] match expected type ?
[error]   val a = Configured[String]
[error]   

After implicit expansion etc. the two method signatures are

def apply[A](f: CfgValue => Option[A]): Configured[A]
def apply[A](implicit f: Configured[A]): Configured[A]

After SAM, they are:

def apply[A](f: CfgValue => Option[A]): Configured[A]
def apply[A](implicit f: CfgValue => Option[A]): Configured[A]

Any way to keep the signatures for 2.12?

Reactormonk
  • 21,472
  • 14
  • 74
  • 123

0 Answers0