RFR: 8357185: Redundant local variables with unconditionally matching primitive patterns [v2]

Chen Liang liach at openjdk.org
Tue Jul 8 14:17:39 UTC 2025


On Fri, 4 Jul 2025 17:41:43 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Further improvements and testing per suggestions
>
> Overall, looks reasonable to me. A stylistic comment for consideration inline.

@lahodaj @biboudis Can you review this again?

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 2834:
> 
>> 2832:     public void visitTypeTest(JCInstanceOf tree) {
>> 2833:         if (tree.expr.type.isPrimitive() || tree.pattern.type.isPrimitive()) {
>> 2834:             JCStatement sideEffect;
> 
> As a mostly stylistic comment: if I were doing this, I would create a variable like: `List<JCStatement> statements;` (or any other name), and then would assign either `List.nil()` or `List.of(...)` to it. That way there would be no `null` checks later.

Passing a nil list still creates a let expression; I don't think I wish to create a redundant let.

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

PR Comment: https://git.openjdk.org/jdk/pull/26107#issuecomment-3049142504
PR Review Comment: https://git.openjdk.org/jdk/pull/26107#discussion_r2192652841


More information about the compiler-dev mailing list