RFR: 8357185: Redundant local variables with unconditionally matching primitive patterns
Aggelos Biboudis
abimpoudis at openjdk.org
Thu Jul 3 14:45:50 UTC 2025
On Thu, 3 Jul 2025 14:41:08 GMT, Chen Liang <liach at openjdk.org> wrote:
>> On the flipside, in the tests we already have this (in `PrimitiveInstanceOfPatternOpWithTopLevelPatterns` but also as a type comparison op in `PrimitiveInstanceOfTypeComparisonOp`):
>>
>>
>> public static int meth() {return 42;}
>> public static boolean exprMethod() {
>> return meth() instanceof int ii;
>> }
>>
>>
>> However this is not sufficient. Can we also add one (one in each file) that actually has side effects and a null check as well and confirm that i is incremented once?
>>
>>
>> static int i = 0;
>> public static Integer meth_sideEffect() { i++; return 42;}
>> public static boolean exprMethod2() {
>> return meth_sideEffect() instanceof int ii;
>> }
>
> Do I just paste this block into both tests and call them in main?
>
> static int sideEffect;
> public static Integer methSideEffect() { sideEffect++; return 42;}
> public static boolean exprMethodSideEffect() {
> sideEffect = 5;
> return methSideEffect() instanceof int ii && sideEffect == 6;
> }
Sure. One with `int ii` and the other with just `int`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26107#discussion_r2182974720
More information about the compiler-dev
mailing list