Next up for patterns: type patterns in switch

Alex Buckley alex.buckley at oracle.com
Fri Aug 14 16:46:35 UTC 2020


On 8/14/2020 4:24 AM, Brian Goetz wrote:> My initial preference was to 
make the guard logic part of the pattern;
> ideally, to make “Pattern && boolean-expr” a pattern.  But this is 
> messy, since it invites ambiguities, and not really needed in the other 
> primary consumer of patterns, since boolean expressions can already be 
> conjoined with &&, and flow scoping already does everything we want. 
> The real problem is switch is too inflexible, a problem revealed when 
> its case labels are made more powerful.  So it seems that the sensible
> thing to do is to make guards a feature of switch, and say a case label 
> is one of:
> 
>      case <constant>
>      case <pattern>
>      case <pattern> when <guard>

Got it, thanks.

Alex


More information about the amber-spec-experts mailing list