Why does Scala implicit resolution fail for overloaded method with type parameter?

前端 未结 1 511
醉梦人生
醉梦人生 2021-01-02 19:33

The first example successfully finds the implicit conversion to the method foo(String), however as soon as I add a type parameter (see fails) the c

相关标签:
1条回答
  • 2021-01-02 19:49

    Both cases seem to fall under this case of the specification:

    Views are applied in three situations:

    ...

    In a selection e.m(args) with e of type T, if the selector m denotes some member(s) of T, but none of these members is applicable to the arguments args. In this case a view v is searched which is applicable to e and whose result contains a method m which is applicable to args. The search proceeds as in the case of implicit parameters, where the implicit scope is the one of T. If such a view is found, the selection e.m is converted to v(e).m(args).

    So it should work. I was actually surprised to see it, because I've never run into the working case before and assumed that there is no implicit search if T has any members named m. I've taken a quick look at http://issues.scala-lang.org/, but couldn't find a relevant issue.

    0 讨论(0)
提交回复
热议问题