RFR: 8347291: Exhaustive switch over a generic sealed abstract class

Liam Miller-Cushon cushon at openjdk.org
Wed Mar 12 22:18:24 UTC 2025


On Fri, 24 Jan 2025 01:08:56 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

> This change avoids javac incorrectly reporting switches like the example in [JDK-8347291](https://bugs.openjdk.org/browse/JDK-8347291) as exhaustive.
> 
> As Jan noted in the bug it seems like the inference behaviour here may not be correct. If it was able to infer a type without crashing that would also avoid the bug.
> 
> However with the current inference behaviour, it's safer to assume that if inference crashes the subtype may need to be handled by the switch, instead of assuming that it doesn't.

I think this is worth considering - the code is already handling an `InferenceException` and working around it in a way that leads to a `MatchException` at runtime. Until it's possible to improve the underlying inference behaviour to not fail, it seems safer to treat types where inference fails conservatively.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23286#issuecomment-2719249427


More information about the compiler-dev mailing list