Closed
Description
Reporting this as a bug because I would argue it's about Scala 2 compatibility.
Minimized code
import annotation.targetName
object Foo {
def apply[A <: Int]: Int = 0
@targetName("applyS") def apply[B <: String]: String = "0"
}
Foo[Int]
Output
scala> import annotation.targetName
|
| object Foo {
| def apply[A <: Int]: Int = 0
| @targetName("applyS") def apply[B <: String]: String = "0"
| }
|
| Foo[Int]
8 |Foo[Int]
|^^^
|Ambiguous overload. The overloaded alternatives of method apply in object Foo with types
| [B <: String] => String
| [A <: Int] => Int
|both match type arguments [Int] and expected type <?>
Expectation
I would expect that to work.
Recently we merged a PR in Scala 2 that fixed it for HKTs: scala/scala#9405
Note that this worked in Scala 2 way before my PR (which is just the natural extension to HKTs):
scala> object Foo {
| def apply[A <: Int]: Int = 0
| def apply[B <: String](implicit dummy: DummyImplicit): String = "0"
| }
object Foo
scala> Foo[Int]
val res5: Int = 0
scala> Foo[String]
val res6: String = 0
If this change is intentional maybe it should be documented in overload-resolution.md