Given that we have incremental compilation, it is not technically feasible. When incrementally recompiling, the compiler only sees a subset of the files comprising a project.
I donât understand why, but I trust your judgment that itâs harder than for private and protected.
âTechnically infeasibleâ seems a bit hard to believe, however. In fact, it is almost possible to simulate package-level sealing within Scala 3, which seems to imply that it is not fundamentally incompatible with incremental compilation.
Oh, so itâs about the exhaustivity checking that sealed is supposed to provide. Sorry, I should have read the previous comments more thoroughly.
So it wouldnât be an issue if sealed[packageName] simply did not provide that added benefit in those cases.
When a match on such a sealed type could not be checked to be exhaustive, a warning could be issued at the site of the match expression, explaining that, unfortunately, that sealed type cannot be checked for exhaustivity due to its scope.
But I see how providing weaker semantics for sealed in these cases might be controversial, even though such a weaker sealed would still be very useful to avoid unwanted extensions (complementarily to private and protected).
Something to consider: the Java implementation of sealed has a corresponding permits clause that lists the permissible extensions.
IIUC Java still doesnât allow multiple top-level classes/interfaces in the same file, so this was an understandable choice on their part, but if we chose to follow suit, we could relax the same-file restriction as well.
It sort of would be an issue, because exhaustivity checking is one of the major benefits of sealed hierarchies. Otherwise, as @sjrd pointed out, itâd would be enough to just make the constructor package private.