Scala 2.13 non exhaustive check on HttpResponse

Why is this match considered to be non exhaustive by the Scala 2.13 compiler?

[error] /acme/Http.scala:90:25: match may not be exhaustive.
[error]       response match {

with the code in question

response match {
  case HttpResponse(StatusCodes.Accepted, _, entity, _) => ()
  case HttpResponse(status, _, entity, _) => ()
}

and HttpResponse being from akka-http-core

// removed some code/comments for clarity
object HttpResponse {
  def apply(...) = new HttpResponse(status, headers, Map.empty, entity, protocol)
  def unapply(any: HttpResponse): OptHttpResponse = new OptHttpResponse(any)
}
final class OptHttpResponse(val get: HttpResponse) extends AnyVal {
  ...
}

See also akka-http/HttpMessage.scala at main · akka/akka-http · GitHub

The warning disappears if I add this to the scalacOptions

    "-Xlint:-strict-unsealed-patmat",

And I know it is because of Check exhaustivity of pattern matches with "if" guards and custom extractors (by default) and of unsealed types (by opt-in). by dwijnand · Pull Request #9140 · scala/scala · GitHub (although the behaviour seems opt-out and not opt-in).

I think it has something to do with sealed types and that final does not equal sealed (which I thought it did). But even with that I’m not sure why the compiler things above code is not matching.

I don’t want to turn off that compiler flag globally - is there way beyond @unchecked or adding a case _ => that I can improve in my code to not have that compiler check fail?

1 Like