RFR: 8372635: Lambdas do not copy over SYNTHETIC flag for local variables

Jan Lahoda jlahoda at openjdk.org
Wed Dec 10 14:22:31 UTC 2025


On Tue, 9 Dec 2025 21:48:24 GMT, Chen Liang <liach at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java line 1155:
>> 
>>> 1153:                     break;
>>> 1154:                 case LOCAL_VAR:
>>> 1155:                     ret = new VarSymbol(sym.flags() & (SYNTHETIC | FINAL), sym.name, sym.type, translatedSym);
>> 
>> this will effectively make synthetic all local variables, should we do this starting from source 27?, what about the parameter being generated below? should it be synthetic too?
>
> This only preserves the SYNTHETIC or FINAL flags of the original sym. I don't think it makes all local vars synthetic, but we should check if these two are the only flags we want to propagate. Or should we switch to a blacklist where we explicitly remove the unwanted flags?
> 
> Also this flag processing should probably be shared by LOCAL_VAR and PARAM.

Exactly - this code should copy the specified flags, if they are set. I.e. if the original variable is not synthetic, the new one won't be synthetic either. If the original variable is synthetic, the flag will be transferred to the new variable.

Given the handling of local variables and parameters is slightly different, I am not sure unifying the flags manipulation is quite feasible.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28724#discussion_r2606855355


More information about the compiler-dev mailing list