I have a case class hierarchy to encode some request and processing errors:
sealed trait OpError sealed trait RequestErrorType sealed trait ProcessingErrorType final case class InvalidEndpoint(reason: String) extends RequestErrorType final case class InvalidParameters(reason: String) extends RequestErrorType final case class InvalidFormat(response: String) extends ProcessingErrorType final case class EntityNotFound(id: Long) extends ProcessingErrorType final case class RequestError(errorType: RequestErrorType) extends OpError final case class ProcessingError(errorType: ProcessingErrorType) extends OpError
If I write a simple match across all patterns:
def printMatches(error: OpError): Unit = error match { case RequestError(InvalidEndpoint(reason)) => //print something case RequestError(InvalidParameters(reason)) => //print something case ProcessingError(InvalidFormat(format)) => //print something case ProcessingError(EntityNotFound(entityId)) => //print something }
the compiler gives me a warning about a missing match:
match may not be exhaustive. It would fail on the following input: ProcessingError(_) def printMatches(error: OpError): Unit = error match {
But ProcessingError accepts in ProcessErrorType with only two extensions: InvalidFormat and EntityNotFound, which are taken into account in pattern matching. What am I missing?
Even more curious, if I change the type of the InvalidParameters or InvalidEndpoint parameter to String *, I will not get the error:
final case class InvalidParameters(reason: String*) extends RequestErrorType
Any ideas?
ssanj source share