Disallowing break label (and continue label) inside an expression switch
    Brian Goetz 
    brian.goetz at oracle.com
       
    Thu Mar  8 19:36:12 UTC 2018
    
    
  
Jan has updated the prototype to make the switch expression a bubble 
penatrable only by exceptions.  Please take a look!
On 3/2/2018 9:30 AM, Remi Forax wrote:
> Hi all,
> as far as i remember, the current idea to differentiate between a break label and a break value is to let the compiler figure this out,
> i wonder if it's not simpler to disallow break label (and continue label) inside an expression switch.
>
> After all, an expression switch do not exist yet, so no backward compatibility issue, it may make some refactoring impossible but had the great advantage to do not allow a lot of puzzler codes like the one below.
>
> enum Result {
>    ONE, MANY
> }
>
> Result result(String[] args) {
>    ONE: for(String s: args) {
>       return switch(s) {
>         case "several":
>         case "many":
>           break MANY;
>         case "one":
>           break ONE;
>         default:
>           continue;
>       };
>    }
>    throw ...;
> }
>
> Rémi
    
    
More information about the amber-spec-experts
mailing list