Bad exhaustive test using Record Pattern as delivered in OpenJDK 19 preview

Michel Turpin michel.turpin1 at gmail.com
Thu Sep 22 22:30:32 UTC 2022


Hello,

First, please excuse me for the way I send this bug report. I cannot find a
way to report it in other ways.

Looking at the description of JEP 405, it made me think of Rust enums and
pattern matching.
I tried then to play on how to write a copy of the Rust "Option" enum :
https://gist.github.com/grimly/55d414f0cc3395e87a7c813176c50ac9

But then I encountered this issue when narrowing the types I use and in
this particular instance (
https://gist.github.com/grimly/55d414f0cc3395e87a7c813176c50ac9#file-testfailing-java-L9-L12
), the compiler throws an error and reports the switch is not exhaustive.

Given in my code "Option" is sealed and may only be "Some" or "None", I
would expect listing both options to make my cases exhaustive.
Adding a default case, I also fail to produce an instance that would
trigger it.

Best regards,
Michel

-- 

Michel TURPIN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20220923/bd7c4313/attachment.htm>


More information about the amber-dev mailing list