There seems to be a problem where scalac is unable to overload methods using implicit classes if the method has a type parameter, even though there isn’t anything in the spec that should forbid this. Originally this was pasted as a stackoverflow question here https://stackoverflow.com/questions/58429854/scala-overloading-method-in-implicit-class however thanks to @martijnhoekstra, he managed to minimize the actual issue here https://scastie.scala-lang.org/C95VbD5dS7OCuqqsDbD5tA code from the scastie is pasted below
class Test {
def rawr(string: String): String = string
}
implicit final class RawrExt(val t: Test) {
def rawr(int: Int): Int = int
}
val t = new Test
t.rawr(5)
class TestP {
def rawr[A](list: List[A]): List[A] = list
}
implicit final class RawrExtP(val t: TestP) {
def rawr(int: Int): Int = int
}
val tt = new TestP
tt.rawr(5) // This doesn't compile
Basically overloading works fine if you have a method without type parameters, i.e. def rawr(int: Int): Int
but as soon as the method does have type parameters, i.e. def rawr[A](list: List[A]): List[A]
then it doesn’t work.
Does anyone have any ideas as to why this is the case?