title: Scala: Pattern matching a generic case class for "concrete" cases
body: <p>let's say I have:</p>
  
  <pre><code>sealed trait Data
  final case class TextData()  extends Data
  final case class ImageData() extends Data
  final case class MetaData[D &lt;: Data](data: D) extends Data
  </code></pre>
  
  <p>I want to pattern match Data objects. I have defined:</p>
  
  <pre><code>def getDataTypeName(data: Data): String ={
      data match {
          case TextData()=&gt;"text"
          case ImageData()=&gt;"image"
          //MetaData(MetaData(_))=&gt;"metaMeta1"  //a
          case _:MetaData[MetaData[_]]=&gt;"metaMeta2"  //b
          //case MetaData(data:Data)=&gt;"meta"+ getDataTypeName(data) //c
          //MetaData(TextData(_))=&gt;"metaMeta1"  //d
          case MetaData(_)=&gt;"meta"
      }
  }
  </code></pre>
  
  <p>I want to be able to see if my data is a meta-metadata, meta-TextData, etc. 
  Line <code>a</code> give me an error, saying:</p>
  
  <blockquote>
    <p>constructor cannot be instantiated to expected type;  found   :
    inst$A$A.MetaData[D]  required: A$A115.this.Data case
    MetaData(MetaData(_))=>"metaMeta1"</p>
  </blockquote>
  
  <p>I would prefer to have something resembling line <code>a</code>. alternatively something like line <code>c</code> would be nice too. </p>
  
  <p>I also tried line <code>b</code>. This one generates some warnings:</p>
  
  <blockquote>
    <p>non-variable type argument A$A115.this.MetaData[<em>] in
    type pattern A$A115.this.MetaData[A$A115.this.MetaData[</em>]] is
    unchecked since it is eliminated by erasure
                case <em>:MetaData[MetaData[</em>]]=>"metaMeta"
                       ^</p>
  </blockquote>
  
  <p>I get this warning for both <code>MetaData[_]s</code>. My understanding is that the said pattern is reduced to _ after type erasure which is consistent with my test results.</p>
  
  <p>I therefore want to know if there is a way of matching against <code>MetaMetaData</code>, <code>MetaTextData</code> ,<code>MetaMetaMetaData</code> etc.</p>
  
  <p>Alternatively, is my design using sealed class in a way they shouldn't be used? What alternative design would you suggest?</p>