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

Python: Don't prune any MatchLiteralPatterns #18738

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tausbn
Copy link
Contributor

@tausbn tausbn commented Feb 11, 2025

Extends the mechanism introduced in #18030 to behave the same for all MatchLiteralPatterns, not just the ones that happen to be the constant True or False.

Extends the mechanism introduced in
#18030
to behave the same for _all_ `MatchLiteralPattern`s, not just the ones
that happen to be the constant `True` or `False`.

Co-authored-by: yoff <yoff@github.com>
Co-authored-by: yoff <yoff@github.com>
@tausbn tausbn marked this pull request as ready for review February 11, 2025 14:21
@Copilot Copilot bot review requested due to automatic review settings February 11, 2025 14:21
@tausbn tausbn requested a review from a team as a code owner February 11, 2025 14:21

Choose a reason for hiding this comment

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

PR Overview

This pull request extends the mechanism for pruning to ensure that no MatchLiteralPattern is ever pruned, avoiding the risk of misidentifying reachable code.

  • The change notes have been updated to reflect the new behavior.
  • The conditional check in the pruner for boolean literal patterns has been removed so that all MatchLiteralPatterns are processed uniformly.

Changes

File Description
python/ql/lib/change-notes/2025-02-11-fix-match-literal-pruning.md Added notes to clarify that no MatchLiteralPattern is pruned
python/extractor/semmle/python/passes/pruner.py Removed conditional pruning for boolean MatchLiteralPatterns to apply the fix universally

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

category: fix
---

- `MatchLiteralPattern`s are now never pruned, as this could lead to code being wrongly identified as unreachable.
Copy link
Collaborator

@adityasharad adityasharad Feb 11, 2025

Choose a reason for hiding this comment

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

Can we add an example so the reader knows what these look like in code?

Suggested change
- `MatchLiteralPattern`s are now never pruned, as this could lead to code being wrongly identified as unreachable.
- `MatchLiteralPattern`s such as `...` are now never pruned from the extracted source code. This fixes some situations where code was wrongly identified as unreachable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants