RFR: 8273328: Compiler implementation for Pattern Matching for switch (Second Preview)
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu Nov 4 13:58:17 UTC 2021
On Thu, 4 Nov 2021 13:16:38 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java line 788:
>>
>>> 786:
>>> 787: private boolean isTransitivelyCovered(Type seltype, Symbol sealed, Set<Symbol> covered) {
>>> 788: DeferredCompletionFailureHandler.Handler prevHandler =
>>
>> Why do we need to guard against completion failures here in Flow?
>
> Consider a case like this:
>
> sealed interface I permits A, B {}
> //A and B defined
> ...
> I i = null;
> switch (i) {
> case A -> {}
> }
>
>
> This will produce an error, because the switch is not exhaustive. Now, consider, in addition, that `B` is missing. It feels a bit harsh to produce an error about the missing `B` permitted subclass (possibly producing that error instead of the exhaustiveness error), as it seems plausible permitted subclasses may be missing during compilation.
Uhm - I get what you say. But isn't sealing meant to be used within a single maintenance domain? If B is missing, how the heck did we get to Flow in the first place (since for sealed classes we check that permitted subclasses extend the sealed class being defined)
-------------
PR: https://git.openjdk.java.net/jdk/pull/6209
More information about the compiler-dev
mailing list