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

Don't issue warnings on dead code #6246

Merged
merged 16 commits into from
Oct 23, 2023
Merged

Conversation

smillst
Copy link
Member

@smillst smillst commented Oct 20, 2023

This should fix the errors in #6221.

Comment on lines 304 to 315
((ExceptionBlock) cur)
.getExceptionalSuccessors()
.forEach(
(key, value) -> {
if (!shouldIgnoreException.apply(key)) {
for (Block b : value) {
if (visited.add(b)) {
worklist.add(b);
}
}
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing this as

        for (Map.Entry<TypeMirror, Set<Block>> entry :
            ((ExceptionBlock) cur).getExceptionalSuccessors().entrySet()) {
          if (!shouldIgnoreException.apply(entry.getKey())) {
            for (Block b : entry.getValue()) {
              if (visited.add(b)) {
                worklist.add(b);
              }
            }
          }
        }

is two lines shorter and I find it easier to read (for example, types are given and there are no lambdas).

I do wish there were a way to bind variables to the parts of the Entry, right in the for statement header.

Comment on lines 346 to 350
List<Node> result = new ArrayList<>();
for (Block b : getAllBlocks(shouldIgnoreException)) {
result.addAll(b.getNodes());
}
return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done with flatMap if you want to make it a one-liner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flatMap would create a new stream for each block:

getAllBlocks(shouldIgnoreException).stream().flatMap(b -> b.getNodes().stream()).collect(Collectors.toList());

collect would be better:

    getAllBlocks(shouldIgnoreException).stream().collect(ArrayList::new, (list, b) -> list.addAll(b.getNodes()), ArrayList::addAll);

But still it creates a Stream object. I think forEach makes the most sense:

getAllBlocks(shouldIgnoreException).forEach(b -> result.addAll(b.getNodes()));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any of those, or the current code, is fine with me.

@mernst mernst assigned smillst and unassigned mernst Oct 21, 2023
@smillst smillst assigned mernst and unassigned smillst Oct 23, 2023
Copy link
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mernst mernst enabled auto-merge (squash) October 23, 2023 16:04
@mernst mernst merged commit 9586f67 into typetools:master Oct 23, 2023
29 checks passed
@mernst mernst deleted the unreachable-nodes2 branch October 23, 2023 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants