Scalac 错误或我的误解?

Scalac bug or misunderstanding on my part?

我在我的 SBT 构建中设置了 -Xfatal-warnings 编译器标志,果然这段代码无法编译:

package example

sealed trait Errors

object Errors {
  case class BadFirstName(name: String) extends Errors
  case class BadLastName(name: String) extends Errors
}

...

def handleError(errors: Errors): String = errors match {
  case BadFirstName(name) => s"$name is bad"
}

我看到错误 [error] It would fail on the following input: BadLastName(_)

但是如果我向 BadFirstName 匹配添加一个守卫,它编译时不会出现错误或警告:

def handleError(errors: Errors): String = errors match {
  case BadFirstName(name) if name.startsWith("t") => s"$name is bad"
}
...
[info] Done compiling.

然后在运行时以可怕的 [error] scala.MatchError: BadLastName(...)

爆炸

这对我来说像是一个错误,但我想检查一下我是否遗漏了什么?

是的,这是一个错误,即SI-5365