Hi,
Here are two things we noticed while migrating code to Scala 2.10.0-M7:
In this example [1]:
trait Marker[A]
object TestImplicit {
implicit val TestImplicit: Marker[Int] = null
}
object SameNameNotWorking {
import TestImplicit._
implicitly[Marker[Int]]
}
the implicit isn't found any more with 2.10 if it is named exactly
like its containing class. I would say that's probably as spec'd
because the imported name is shadowed by the (top level) name defined
in the same source file. Workaround: rename the implicit.
Here is another more interesting one [2]:
object InferenceChange {
implicit object StringMarker extends Marker[String]
def getWithMarker[T: Marker]: T = null.asInstanceOf[T]
def func[A: Marker]: Option[A] =
if (true)
None
else
Some(getWithMarker)
}
Here the error message is this:
[error] src/main/scala/InferenceChange.scala:10: ambiguous implicit values:
[error] both object StringMarker in object InferenceChange of type
InferenceChange.StringMarker.type
[error] and value evidence$2 of type Marker[A]
[error] match expected type Marker[T]
[error] Some(getWithMarker)
It seems that the expected type of `func` is not any more regarded for
determining type constraints for the `getWithMarker` call before
looking for implicits. I don't know if it is expected but it means
that in those cases you now need to specify type arguments more often
than before. This may become unwieldy if `getWithMarker` would take
several parameters which could be inferred otherwise. Workaround:
specify the type argument for the getWithMarker call.
I suspect there are several other changes like those, is anyone
collecting for a migration guide?
--
Johannes
[1]
https://gist.github.com/3496686#file_src/main/scala/same_name_not_working.scala
[2]
https://gist.github.com/3496686#file_src/main/scala/inference_change.scala
-----------------------------------------------
Johannes Rudolph
http://virtual-void.net