In short
trait Foo; trait Bar
object Test {
def apply(implicit foo: Foo) {}
def apply(implicit bar: Bar) {}
}
Test.apply // ambiguous
Scala doesn't resolve overloading by figuring out if only one of the two implicits is available.
You should use the magnet pattern if you want overloading in such a case.
object FooOrBar {
implicit def fromFoo(implicit f: Foo) = FooOrBar(Left(f))
implicit def fromBar(implicit b: Bar) = FooOrBar(Right(b))
}
case class FooOrBar(e: Either[Foo, Bar])
object Test {
def apply(implicit i: FooOrBar) = i.e match {
case Left (f) => "foo"
case Right(b) => "bar"
}
}
Test.apply // could not find implicit value for parameter i: FooOrBar
implicit val f = new Foo {}
Test.apply // "foo"