【发布时间】:2020-05-19 11:58:43
【问题描述】:
为什么被密封类型绑定的类型参数似乎not 会引发穷举警告
sealed trait A
case class B() extends A
case class C(i: Option[Int]) extends A
def f[T <: A](a: T) =
a match {
case B() =>
case C(None) =>
}
f(C(Some(42))) // throws MatchError
虽然没有类型参数
def f(a: A) =
a match {
case B() =>
case C(None) =>
}
发出警告
warning: match may not be exhaustive.
It would fail on the following input: C(Some(_))
a match {
^
【问题讨论】:
-
听起来像个错误。
标签: scala pattern-matching compiler-warnings type-parameter non-exhaustive-patterns