On Thu, 20 Apr 2023 14:07:01 GMT, Vicente Romero <[email protected]> wrote:
>> The intent here is to avoid eager initialization of enums - so, until the
>> enum is initialized, `lazyDoEnumSwitch` will be used (which, by itself,
>> won't compute any results, except the result for `null`), which is then
>> replaced with `doEnumSwitch` using the enum constants directly.
>>
>> The enum switches support patterns as well, so something like:
>>
>> enum E {A;}
>> E e = ...;
>> switch (e) {
>> case E ee -> {}
>> }
>>
>> is valid, and should trigger the part with Class labels.
>
> yep I found a similar test case triggering this code
could you explain a bit more the relation between `lazyDoEnumSwitch` and
`doEnumSwitch` because my understanding is that `lazyDoEnumSwitch` is invoking
`doEnumSwitch` so to me whenever `lazyDoEnumSwitch` is invoked there will be an
immediate invocation of `doEnumSwitch` that's why I thought they could be
folded together
>> `startIndex` may be non-0 when there are guards in the switch. In the case
>> of the `enumSwitch`, something like:
>>
>> enum E {A, B;}
>> E e = E.B;
>> switch (e) {
>> case E ee when ee == E.A -> {}
>> case E ee -> {}
>> }
>>
>>
>> the method will be called twice, one with `startIndex == 0` and once with
>> `startIndex == 1`, after the guard fails/returns `false`.
>
> I see, thanks
and regarding checking that `startIndex` should be `>= 0`? shouldn't we check
for that?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13074#discussion_r1172839418
PR Review Comment: https://git.openjdk.org/jdk/pull/13074#discussion_r1172840817