[#826] | project: api | priority: medium | category: bug | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Nikolay | Burak | fixed | 2006-11-16 16:25:16.0 | |
subject | [contrib #252] ambiguous reference to overloaded definition | |||
code |
package bug.contrib252 object Test { def main(args: Array[String]): Unit = { Console.println(args.indexOf((s: String) => s == "xxx")) } } |
|||
what happened | contrib_252.scala:5 error: erroneous reference to overloaded definition, most specific definition is: method indexOf in trait Iterable of type ((java.lang.String) => scala.Boolean)scala\ .Int, yet alternative definition method indexOf in trait Seq of type [B >: java.lang.String](B)scala.Int is defined in a subclass Console.println(args.indexOf((s: String) => { Console.println(s); s == "xxx"})) ^one error found |
|||
what expected | Successful compilation | |||
[back to overview] |
Nikolay edited on 2006-11-16 16:30:26.0 |
The strange thing is this compiles with scala-2.2.0 but calls the wrong (wrt to the signature) method - the one in Seq instead of the one in Iterable. Or maybe the current commpiler correctly identifies some error, which would be unfortunate because it would mean method indexOf is unusable for sequences
|
Nikolay edited on 2006-11-16 16:31:54.0 |
fixed "the what happened" mesage |
Martin edited on 2006-11-17 18:24:46.0 |
In fact, the new version of nsc is right, and it is a problem of too aggressive overloading in the libraries. The point to note is that the method in Seq *is* applicable to the argument. Here's the method:
def indexOf[B >: A](elem: B): Int = ...To apply this to an argument of type String => boolean , simply instantiate B to AnyRef!
The new compiler correctly recognizes that both versions are applicable, and that the best one is shadowed by another one in a subclass. So it is correct in complaining.
What to do? I think we need to redesign this part of the library. Maybe rename the version in Itarable to
I rassigned to Burak, since he's the ucrrent keeper of the collection libraries. |
Martin edited on 2006-11-17 18:25:48.0 |
Burak edited on 2006-11-20 17:19:36.0 |
In Iterable, I renamed indexOf(fun) to findIndexOf(fun) , because there is already find(fun) .
Then, I moved the indexOf(elem) method up in the hierarchy from Seq to Iterable, since it does not need the length method.
Consequently, the code above should now use findIndexOf .
|