As has been discussed many times on SO, a Scala match will warn you if you don't exhaustively list all of the types deriving from a sealed class.
What I want is a compile-time generated Iterable of the case objects deriving from a particular parent. Alternatively, I'd be happy with a way to make the compiler tell me I don't have all of the necessary types in some Iterable. I don't want a run-time, reflection-based approach.
As an example of the second approach, I'd like to have the following rough code generate a compile error where indicated.
sealed trait Parent
case object A extends Parent
case object B extends Parent
case object C extends Parent
// I want a compiler error here because C is not included in the Seq()
val m = Seq(A, B).map(somethingUseful)
Feel free to answer by telling me it's not possible. It just seems like it should be possible at some level because the compiler must be doing essentially the same work when determining a match is non-exhaustive.
Thinking about it another way, I'd take something like the Enumeration.values() method except applied to case objects. Certainly, I could add something similar to the code above with a manually maintained list of values to the parent's companion object, but that seems needlessly error-prone when the compiler could do that for me.
// Manually maintained list of values
object Parent {
val values = Seq(A, B, C)
}