RFR: 8300543 Compiler Implementation for Pattern Matching for switch [v5]

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Apr 24 13:54:03 UTC 2023

On Mon, 24 Apr 2023 12:53:59 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> In this case, as long as the union type could only be present at the top level (as opposed to e.g. a type of a record component), we could simply require all components to be covered for union types for exhaustiveness in `checkCovered`, no? We could do something different, if we had a good reason, but enhancing `checkCovered` should be enough, and shouldn't be too difficult (as long as the spec would say so). Do I miss something?

I believe that is a correct assessment. Technically speaking though, I'm not sure the JLS can be enhanced to do that - given that, as Remi reminded me, union types are not a thing. The _declaration_ of a union type parameter is a thing, but then the underlying declared type of the parameter is just the LUB. This means that the JLS can't track which expressions have union types. Note that saying stuff like `if the selector expression is a multi-catch parameter` won't work either, given that with `var` you can alias that on a different local. So, if things are not wired up a the type level (as it is currently the case), there's not much we can do I'm afraid.


PR Comment: https://git.openjdk.org/jdk/pull/13074#issuecomment-1520200078

More information about the compiler-dev mailing list