title: Scala: Mix traits and case class in pattern match
body: <p>I want to match on some case classes. If I don't know them, I want to match on a specified trait the classes have to extend. This looks like</p>
  <pre><code>trait Event  //root trait
  trait Status extends Event  //special trait
  trait UIEvent extends Event //special trait
  
  case class Results extends Event   //concrete case class
  case class Query extends Event     //concrete case class
  
  case class Running extends Status  //concrete case class
  case class Finished extends Status //concrete case class
  
  case class Update extends UIEvent  //concrete case class
  </code></pre>
  <p>I run the following test</p>
  <pre><code>  val events = List(Results, Query, Running, Finished, Update)
      events foreach {
        case Results =&gt; println(&quot;Got a Results&quot;)
        case Running =&gt; println(&quot;Got a Running&quot;)
        case s:Status =&gt; println(&quot;Got some StatusEvent&quot;)
        case ui:UIEvent =&gt; println(&quot;Got some UIEvent&quot;)
        case e: Event =&gt; println(&quot;Generic Event&quot;)
        case x =&gt; println(&quot;Didn't matched at all &quot; + x)
      }
      println(&quot;############################&quot;)
      val STATUS = classOf[Status]
      val EVENT = classOf[Event]
      val UIEVENT = classOf[UIEvent]
      val RESULTS = classOf[Results]
      val eventsClass = events map (_.getClass)
      eventsClass foreach {
        case RESULTS =&gt; println(&quot;Got a Results&quot;)
        case STATUS =&gt; println(&quot;Got some StatusEvent&quot;)
        case UIEVENT =&gt;  println(&quot;Got some UIEvent&quot;)
        case EVENT =&gt; println(&quot;Generic Event&quot;)
        case x =&gt; println(&quot;Didn't matched at all &quot; + x)
      }
  </code></pre>
  <p>which leads to the following output</p>
  <pre><code>Got a Results
  Didn't match at all Query
  Got a Running
  Didn't match at all Finished
  Didn't match at all Update
  ############################
  Didn't match at all class de.mukis.scala.test.main.Results$
  Didn't match at all class de.mukis.scala.test.main.Query$
  Didn't match at all class de.mukis.scala.test.main.Running$
  Didn't match at all class de.mukis.scala.test.main.Finished$
  Didn't match at all class de.mukis.scala.test.main.Update$
  </code></pre>
  <p>Why can't I pattern match on case class and traits or just only on the class?</p>