Overload resolution with generic implicit only works when there are no parameters #11885
Given the choice between two functions with the following properties:
Then the compiler successfully resolves the overload if the list of explicit parameters common to both functions is undefined, whereas it fails to resolve the overload if the list of explicit parameters is defined (even if it is empty).
Available on scastie for those who want to run it.
case class Wrap[A](value: A) implicit val wrap: Wrap[Int] = Wrap(5) // resolution between no parameter and one parameter (which is implicit) succeeds def foo1: Seq[Int] = 1 :: 2 :: Nil def foo1[B](implicit wrap: Wrap[B]): Seq[B] = wrap.value :: Nil println(foo1) // (1, 2) println(foo1[Int]) // (5) // resolution between one parameter and two parameters (one of which is implicit) fails // note: would also fail is the list of parameters is () def foo2(bar: Int): Seq[Int] = Seq.fill(bar)(1) ++ Seq.fill(bar)(2) def foo2[C](bar: Int)(implicit wrap: Wrap[C]): Seq[C] = Seq.fill(bar)(wrap.value) println(foo2(3)) // would expect (1, 1, 1, 2, 2, 2) but fails to resolve overload println(foo2[Int](3)) // (5, 5, 5)
Tested on Scala 2.13.1 and 2.12.10.
I am not sure which of the two behaviours is correct (should it successfully resolve or not?), but it is disconcerting that it changes based on the presence of explicit parameters.
This seems normal (or normalized) to me, because you take applicable alternatives and pick between them based on the first parameter list.
However, fixed in dotty .22.