If I use an unsealed trait
or abstract class
in Scala and then use pattern matching, I wonder, does the compiler not know at compile time for this particular patternmatch what possible implementations of this trait/class are available? So, if it does, could it not give pattern match warnings even though that the trait
/abstract class
is not sealed because he knows which types could be used, by checking all the possible dependencies/imports?
E.g. if I have an Option[A]
and I do pattern matching only for Some[A]
but not for None
, the compiler will complain, because Option
is sealed.
If the compiler can't know/resolve that, then why can't he? And if the compiler (theoretically) can do that, what are the reasons for that it is not used in Scala? Are there other languages which support that kind of behaviour?