Re: [patterns] Several patterns and guards

2023-08-14 Thread Tagir Valeev
Hello! On Mon, Aug 14, 2023 at 5:44 PM Brian Goetz wrote: > > So, there are two stable points here: make the where clause part of the > pattern, or match it with the case label entirely. The middle option is not > stable; a case like > > case P, Q when e: > > Is no longer clear Exactly, i

Re: [patterns] Several patterns and guards

2023-08-14 Thread Guy Steele
Or you could just require parentheses when the meaning might not be clear. And I mean _require_: allow case P when e: case P, (Q when e): case (P, Q) when e: but NOT case P, Q when e: And if you object that case (P, Q) when e: should really mean a single tuple pattern (P,

Re: [patterns] Several patterns and guards

2023-08-14 Thread Brian Goetz
So, there are two stable points here: make the where clause part of the pattern, or match it with the case label entirely. The middle option is not stable; a case like case P, Q when e: Is no longer clear, and worse, if the when clause binds to Q, then we would have to repeat the guard i

Re: [patterns] Several patterns and guards

2023-08-14 Thread Remi Forax
- Original Message - > From: "Tagir Valeev" > To: "Brian Goetz" > Cc: "amber-spec-experts" > Sent: Monday, August 14, 2023 5:28:19 PM > Subject: Re: [patterns] Several patterns and guards > I don't think that my example is contrived. Let's think of it from > another angle. Are multiple

Re: [patterns] Several patterns and guards

2023-08-14 Thread Tagir Valeev
> And also the formatting does not help, you can compare Of course, if you know the confusing semantics of the language, you can format the code to make it less confusing. We can also provide IDE warnings or autoformatting to help the users to avoid confusion. But it's always better to make the la

Re: [patterns] Several patterns and guards

2023-08-14 Thread Tagir Valeev
I don't think that my example is contrived. Let's think of it from another angle. Are multiple patterns in the same switch label useful or contrived? If not useful, then let's disable them completely. If useful, then the next question: are guards with multiple patterns useful or contrived? Can you

Re: [patterns] Several patterns and guards

2023-08-14 Thread Remi Forax
- Original Message - > From: "Brian Goetz" > To: "Tagir Valeev" > Cc: "amber-spec-experts" > Sent: Monday, August 14, 2023 5:04:19 PM > Subject: Re: [patterns] Several patterns and guards > While we could certainly do this, I think the cost-benefit runs in the wrong > direction here. T

Re: [patterns] Several patterns and guards

2023-08-14 Thread Brian Goetz
While we could certainly do this, I think the cost-benefit runs in the wrong direction here. This sort of thing is better expressed as an if, and that’s fine. (I think you’ll agree that this example is a little bit contrived.). > On Aug 14, 2023, at 5:15 AM, Tagir Valeev wrote: > > Hello! >

[patterns] Mixed constant-pattern cases

2023-08-14 Thread Tagir Valeev
Hello! I've noticed that javac accepts this code: enum X {A, B} void test(Object obj) { switch (obj) { case String _, X.B -> System.out.println("B or String"); default -> System.out.println("other"); } } public static void main(String[] args) { new Test().test("ddd"); } At the sa

[patterns] Several patterns and guards

2023-08-14 Thread Tagir Valeev
Hello! Currently, when the switch label contains several patterns, only one guard could be declared, which is applied to all the patterns at once. In other words, the following code is not possible: void test(Object obj) { switch (obj) { case Integer _ when ((Integer) obj) > 0, Str