RFR: 8291769: Translation of switch with record patterns could be improved [v6]
Jan Lahoda
jlahoda at openjdk.org
Fri Sep 30 12:26:27 UTC 2022
On Tue, 27 Sep 2022 23:40:12 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Jan Lahoda has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains eight commits:
>>
>> - Merge branch 'master' into JDK-8291769
>> - Merge branch 'master' into JDK-8291769
>> - Reflecting review feedback.
>> - Merge branch 'master' into JDK-8291769
>> - Using a custom record instead of a generic Pair.
>> - Fixing test.
>> - Properly handle null record components.
>> - 8291769: Translation of switch with record patterns could be improved
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java line 369:
>
>> 367: nestedPatterns = nestedPatterns.tail;
>> 368: }
>> 369: Assert.check(components.isEmpty() == nestedPatterns.isEmpty());
>
> is it possible for this assertion not to hold under some conditions? can it be removed?
This is mostly to ensure that if there would be a bug in `Attr` that would not produce an error in case the number of record components, and the number of nested patterns would not match, javac will fail consistently.
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java line 403:
>
>> 401: ? syms.objectType
>> 402: : selector.type;
>> 403: Assert.check(preview.isEnabled());
>
> side: not part of your patch but, do we need to check if preview is enabled at this point?
The ordinary checks should have happened in the parser and/or `Attr`, this is mostly s safeguard in case some of the checks would be missing for any reason.
-------------
PR: https://git.openjdk.org/jdk/pull/9746
More information about the compiler-dev
mailing list