RFR: 8372635: Lambdas do not copy over SYNTHETIC flag for local variables [v2]
Chen Liang
liach at openjdk.org
Thu Dec 11 18:20:55 UTC 2025
On Thu, 11 Dec 2025 13:58:28 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> Consider case like:
>>
>> Object o = ...;
>>
>> //synthetic variable for the instanceof's expression
>> boolean b = o.toString() instanceof String str && str.isEmpty();
>>
>> Runnable r = () -> {
>> //synthetic variable for the instanceof's expression
>> boolean b = o.toString() instanceof String str && str.isEmpty();
>> };
>>
>>
>> There are synthetic variables generated for `o.toString()`, to ensure the method is invoked only once for each `instanceof`. These variables are marked as synthetic in `TransPatterns` (and then consequently omitted in `LocalVariableTable`), but when the flag is lost for the variable in the lambda.
>>
>> This PR proposes to keep the flag, as suggested in the bug.
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>
> Copy all flags when creating lambda local var/parameter.
Lgtm assuming there is no test failure
-------------
Marked as reviewed by liach (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/28724#pullrequestreview-3568730903
More information about the compiler-dev
mailing list