Skip to content

Conversation

@PhantomInTheWire
Copy link
Member

@PhantomInTheWire PhantomInTheWire commented Dec 30, 2025

fixes: #1243
previous/reference pr: #1552

Summary

  • Adds a new "Apply De Morgan's Law" code action for refactoring complement expressions
  • Supports both boolean operators (!, &&, ||) and bitwise operators (~, &, |)
  • Automatically handles operator precedence by adding parentheses where needed
  • Simplifies double negations (e.g., !!a → a) when possible
  • Includes comprehensive tests covering nested expressions, ternary operators, and edge cases
Screen.Recording.2026-01-03.at.17.03.42.mov

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks a lot! The algorithm looks great! 🤩 I left some smaller comments inline.

@PhantomInTheWire
Copy link
Member Author

@ahoppen should be good to review

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Very nice. I have a few more small comments inline.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Also: When #2414 is merged, you can add the new refactoring action to the documentation

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Let’s 🚢 it

@ahoppen
Copy link
Member

ahoppen commented Jan 6, 2026

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Jan 6, 2026

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 5639a0f into swiftlang:main Jan 7, 2026
3 checks passed
ahoppen pushed a commit that referenced this pull request Jan 13, 2026
fixes: #1569

mostly works but not sure what to do with many edge cases and has a todo
for switch statements, also this will probably have conflicts with
#2406 marking as draft
till that merges and i can resolve the conflicts.


https://github.com/user-attachments/assets/a6d07f9d-6f09-4330-8cd0-2d24bd6973fb

---------

Signed-off-by: Karan <[email protected]>
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.

Code action to apply DeMorgan's law

2 participants