Scalac bug或我的误解?

时间:2018-06-08 16:10:56

标签: scala scalac

我在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(...)

炸毁

这对我来说似乎是一个错误,但我想检查一下我是否错过了什么?

1 个答案:

答案 0 :(得分:1)

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