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