Implicit resolution fails for overloaded method with type parameter
See original GitHub issueDotty seems to have inherited this issue from Scala: https://github.com/scala/bug/issues/9523
object works {
class A {
def foo(): String = ???
}
implicit class PimpedA(a: A) {
def foo(i: String): String = ???
}
val a = new A()
a.foo("test") //compiles
}
object fails { //same as `works`, but adds type parameter
class A {
def foo[T](): String = ???
}
implicit class PimpedA(a: A) {
def foo[T](i: String): String = ???
}
val a = new A()
PimpedA(a).foo("test") // compiles
a.foo("test") // error: too many arguments for method foo: (): String
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Implicit resolution fails for overloaded method with type ...
The first example successfully finds the implicit conversion to the method foo(String), however as soon as I add a type parameter (see fails)...
Read more >Why does Scala implicit resolution fail for ... - Stack Overflow
The first example successfully finds the implicit conversion to the method foo(String) , however as soon as I add a type parameter (see...
Read more >Why does Scala implicit resolution fail for overloaded method ...
In a selection e.m(args) with e of type T , if the selector m denotes some member(s) of T , but none of...
Read more >How does overload resolution interact with implicit conversions?
I failed to find information on the role of implicit conversions in overload resolution. Is there a way to make the compiler try...
Read more >Overload resolution failed because no accessible '<method ...
You have made a call to an overloaded method, but the compiler has found two or more overloads with parameter lists to which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The attempted fix in scalac is still not merged.
The best summary is from @adriaanm’ on scala/scala#7396:
So, one can argue that the compiler and the spec actually agree: It’s not a selection
e.m(args)
but a selectione.m[T](args)
. Of course the[T]
is inserted by type inference, so this now depends on the way rules in the spec are ordered.To fix this on the typer side would be very messy, I fear. This is also born out by the fact that the attepted fix in scalac did not make it in so far. So I prefer to declare the status quo as law and fix it on the spec side.
Fixed by https://github.com/lampepfl/dotty/pull/12719