为什么这种使用对象类型的匹配类型等同于 Nothing?

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

在 Dean Wampler 的书中,Programming Scala, 3rd Edition, there is an example 有:

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] 

似乎没有解释,至少在周围的上下文中,为什么 summon[Elem[Nil.type] =:= Nothing] 而不是 summon[Elem[Nil.type] =:= Nil.type]。为什么会这样?

正如评论中所建议的那样,Nil 扩展了 List[Nothing],因此您的 case IterableOnce[t] => t 适用并且 Elem[Nil.type] =:= Nothing.