|
[#980] |
project: compiler |
priority: low |
category: missing feature |
|
submitter |
assigned to |
status |
date submitted |
|
Burak |
Martin |
won't fix |
2007-03-07 10:26:57.0 |
subject |
sometimes less inference would be more |
code |
Console.println(List(1,2,3) indexOf { x:Int => x % 2 == 0 })
// what was meant was: findIndexOf |
what happened |
This compiles and executes, but with a somewhat strange result if one is deceived by the method name:
tsf-wpa-2-180:~/Documents/svn/scala buraq$ ./build/quick/bin/scala -nocompdaemon /tmp/gagaga.scala
-1
|
what expected |
Just like with equality ==, the parametric polymorphism seems to defeat the purpose of the type system in some cases. List contains the method
def indexOf[B >: A](elem: B): Int = ...
so the type of the anonymous function is simply bumped up to AnyRef :-(:-( It would be nice if the user had more fine-grained control over inference that calls lower bounded methods.
The present behavior is very good for method ::, but I claim most uses of lower bounds on type parameters of method are only there to have covariance for some type parameter A of the enclosing class. This would be a use case for an attribute "@don't infer type argument if it is not exactly A" def indexOf. |
[back to overview] |