<div dir="ltr"><div>Hi all,<br><br>I'm new to the list—apologies if this has been discussed before, and thanks in advance for your time.<br><br>I have a question about pattern matching with sealed types. Consider this example:<br><br>sealed interface A permits B, C {}<br>record B(String b1, String b2) implements A {}<br>record C(String c) implements A {}<br><br>A myVar = ...;<br>if (!(myVar instanceof B(var b1, var b2))) {<br>    return switch (myVar) {<br>        case C(var c) -> c;<br>        case B b -> throw new IllegalStateException("should not happen");<br>    };<br>}<br>// use b1, b2<br><br>Here, I want to keep an early-return style, but since I need to return a value from C, I have to use a switch. This leads to redundancy: we've already tested myVar is not a B, so that case should be statically unreachable.<br><br>My questions:<br><br>1. Is there any consideration or ongoing work to allow the compiler to automatically eliminate such unreachable cases?<br><br>2. If only one case remains (in this case, C), could it be possible to treat the variable as a C directly without requiring an explicit switch?<br><br>Again, apologies if this has already been discussed. I'd appreciate any pointers to relevant threads or JEPs if so.<br><br>Thanks,<br></div>Andreas</div>