pattern matching bug

Brian Goetz brian.goetz at oracle.com
Thu Oct 25 16:30:00 UTC 2018


Correct.  The RHS must either be an expression or complete abruptly for reason “break-with-value”.  

Also, the example falls afoul of exhaustiveness; we should be able to prove that the default branch is dead (the switch is not nullable, because it has no nullable cases, and the String case is total.  So the default should be dead.)  

> On Oct 25, 2018, at 12:17 PM, Jan Lahoda <jan.lahoda at oracle.com> wrote:
> 
> Hi Remi,
> 
> Thanks for the report. I've filled this as:
> https://bugs.openjdk.java.net/browse/JDK-8212982
> 
> I believe this program should not compile (for switch expressions with rule cases, the case shouldn't complete normally).
> 
> Jan
> 
> On 24.10.2018 12:08, Remi Forax wrote:
>> Using the amber-demo branch, this code prints bug *and* temp :)
>> Again this bug was found by Francois Green.
>> 
>> public class SwitchBug {
>> 
>>     static String hold(String item) -> switch(item) {
>>       case String s -> { System.out.println(s); }
>>       default -> "temp";
>>     }
>> 
>>     public static void main(String[] args) {
>>         System.out.println(hold("bug"));
>>     }
>> }
>> 
>> Rémi
>> 



More information about the amber-dev mailing list