Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix one if cleanup to watch for PatternInstanceof nodes #1201

Merged
merged 2 commits into from
Mar 9, 2024

Conversation

jjohnstn
Copy link
Contributor

What it does

Fixes single if cleanup to handle case of pattern instanceof expressions.

How to test

See issue or new test.

Author checklist

@jjohnstn jjohnstn self-assigned this Feb 16, 2024
@jjohnstn jjohnstn added the bug Something isn't working label Feb 16, 2024
@jjohnstn jjohnstn added this to the 4.32 M1 milestone Feb 16, 2024
- fixes eclipse-jdt#1200
- add new PatternInstanceof logic to
  OneIfRatherThanDuplicateBlocksThatFallThroughFixCore
- add new test to CleanUpTest16
@jjohnstn jjohnstn force-pushed the donotmergeinstanceofs branch from a1fc624 to 733c313 Compare March 9, 2024 03:50
@jjohnstn jjohnstn merged commit 16ca3ea into eclipse-jdt:master Mar 9, 2024
9 checks passed
@jjohnstn jjohnstn deleted the donotmergeinstanceofs branch March 9, 2024 04:50
@dg444
Copy link

dg444 commented Jan 11, 2025

This issue is not fixed in Eclipse 4.34.0 2024-12.
Example1:

if (number instanceof Long n) {
return n.toString();
}
else if (number instanceof Float n) {
return n.toString();
}
else if (number instanceof Double n) {
return n.toString();
}

=> fails to compile:

if ((number instanceof Long n) || (number instanceof Float n) || (number instanceof Double n)) {
return n.toString();
}

Example 2:

if (e instanceof IOException io)
throw io;
else if (e.getCause() instanceof IOException io)
throw io;

=> fails to compile:

f ((e instanceof IOException io) || (e.getCause() instanceof IOException io))
throw io;

@dg444
Copy link

dg444 commented Jan 11, 2025

For more information see https://bugs.eclipse.org/bugs/show_bug.cgi?id=570171

@jjohnstn
Copy link
Contributor Author

This has been fixed. There are 2 cleanups that create one if. One combines multiple if statements and the other merges conditions of an if/else if/else statement. The first cleanup was fixed in March by this PR. The second cleanup has just been fixed for 2025-03 M2. See #1200 for details on the new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Single if cleanup should not concatenate instanceofs that use pattern matching
2 participants