Why does this match type employing object types equate to Nothing?

59 views Asked by At

In Dean Wampler's book, Programming Scala, 3rd Edition, there is an example with:

type Elem[X] = X match
  case String => Char
  case IterableOnce[t] => t
  case Array[t] => t
  case ? => X 

summon[Elem[List[Int]] =:= Int]
summon[Elem[Nil.type] =:= Nothing] 

It doesn't seem to be explained, at least in the surrounding context, why summon[Elem[Nil.type] =:= Nothing] and not summon[Elem[Nil.type] =:= Nil.type]. Why is this the case?

1

There are 1 answers

0
Gaël J On BEST ANSWER

As suggested in the comments, Nil extends List[Nothing], thus your case IterableOnce[t] => t applies and Elem[Nil.type] =:= Nothing.