title: How can I verify type existence on compile time in Scala
body: <p>I have the following traits and classes:</p>
  
  <pre class="lang-scala prettyprint-override"><code>sealed trait Signal
  
  sealed trait Description[T]
  
  final case class S1(name: String) extends Signal
  
  final case class D1(name: String) extends Description[S1]
  </code></pre>
  
  <p>What I try to achieve is that anyone who wants to add Signal will have (at compile time) to create a description.</p>
  
  <p>I don't want to change the signature of <code>Description</code> but for sure not of <code>Signal</code></p>
  
  <p>I set my compiler to fail on warning, so I can leverage the fact that my ADT is sealed.</p>
  
  <p>My idea was to have such a "compilation guard":</p>
  
  <pre class="lang-scala prettyprint-override"><code>def compilationGuard[S &lt;: Signal](s: S): Description[S] = s match { case S1(name) =&gt; D1(name) }
  </code></pre>
  
  <p>but I get the following error:</p>
  
  <pre><code>&lt;console&gt;:17: error: type mismatch;
   found   : D1
   required: Description[S]
         def compilationGuard[S &lt;: Signal](s: S): Description[S] = s match { case S1(name) =&gt; D1(name) }
                                                                                                ^
  </code></pre>