scala - Why does map/filter ... not work with an Array of Nothing? -


isn't nothing subtype of types?

scala> val array = new array(5) array: array[nothing] = array(null, null, null, null, null)  scala> array.map(_ => 42) <console>:9: error: value map not member of array[nothing]        array.map(_ => 42)              ^  scala> array.filter(_ != 42) <console>:9: error: value filter not member of array[nothing]        array.filter(_ != 42)              ^ 

it's weird doesn't work.

is specified, feature or bug?

when see weird behavior involving nothing, it's because type inference algorithm thinks inserted nothing itself, since introduced during type inference: if nothing known type variable bounded , nothing. has long been on list of things see if can introduce new internal-only bottom type purpose user-level nothing , inference-level nothing not intermingled, it's pretty ambitious task. still, might hardcore enough try it.


Comments