case null and type pattern

Remi Forax forax at univ-mlv.fr
Sun Jul 18 17:34:27 UTC 2021


----- Original Message -----
> From: "Manoj Palat" <manoj.palat at in.ibm.com>
> To: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Sent: Jeudi 15 Juillet 2021 00:43:40
> Subject: case null and type pattern

> Hi Gavin, All,

HI Manoj,

> 
> In
> http://cr.openjdk.java.net/~gbierman/jep406/jep406-20210608/specs/patterns-switch-jls.html#jls-14.30.1,
> Section 14.11, I see "If a switch label has a null case label element then if
> the switch label also has any pattern case element labels, they must be type
> patterns (14.30.1)." implying that the following code:
> 
> private static void foo(Object o) {
> switch (o) {
> case null, Integer i && i > 10 -> System.out.println(0); // flag error?
> default -> System.out.println(o);
> }
> should have an error flagged for case label with null since the pattern case
> label element is not a type pattern but a guarded pattern.
> Any reason for excluding guarded patterns here? Or does this requires a
> modification in spec to include guarded patterns as well?

For me, a guarded pattern or a parenthesis pattern are kind of composite patterns,
you need to take a look at what's inside. 

But I'm letting Gavin answer to your specific questions.

> 
> Regards,
> Manoj

regards,
Rémi


More information about the amber-spec-observers mailing list