Sure - but this logic is only applied to switch expression featuring
enums AFAIK - switch statements with enums are non-exhaustive (and I
think that will have to stay that way).
Maurizio
On 27/10/2023 15:28, Brian Goetz wrote:
Unfortunately enum is that one case where compatibility dictates that
we can't be exhaustive, which is a little sad... but I think that's
the best we can do?
What we do for enums is do exhaustiveness checking based on the
compile-time state of the world, and generate a synthetic default
clause that deals with separately-compiled changes. (Same with sealed
types.) This works pretty well, as it lets us type-check a (new)
switch like
int wavelengthNm = switch (trafficLightColor) {
case RED -> 700;
case YELLOW -> 580;
case GREEN -> 540;
}
and not require a "silly" default, while offering runtime protection
against novel colors showing up at runtime, and notifying the user at
a subsequent compile if something unexpectedly changed.