I encountered this very peculiar behaviour that had me stumped for quite awhile. I've re-created it in a simple snippet below, code is lifted from Scala wrapper.
scala> def a = {
| implicit val u = null
| val x: Int = List(1,2,3).map(_.toString)
| }
a: Unit
In the code above, there is no error thrown even though I know the type of val x to be List[String]. I can change the type of x to Int, Long, etc. and it will continue to compile fine.
However when I add explicitly state a type for the implicit val u, like in the example below, the compiler behaves as expected and throws an error.
scala> def a = {
| implicit val u: Any = null
| val x: Int = List(1,2,3).map(_.toString)
| }
<console>:10: error: type mismatch;
found : List[String]
required: Int
Has anyone else experienced this or has any insight into why this is happening?
nulland implicits without explicit types. - Michael Zajacimplicit val u = nullsays "I want to put an implicit value in scope for any type whatsoever and I want everything to blow up at runtime whenever that value is used". - Travis Brownimport language._thingies. Might as well put those unused nulls to work. - som-snytt