Skip to content

Conversation

maks-rafalko
Copy link
Contributor

@maks-rafalko maks-rafalko commented Oct 18, 2025

This is only a reproducer for the issue reported in #1119

@maks-rafalko maks-rafalko changed the title Add reproducer for #1119 Reproducer for a bug with format-preserving printer that loses parentheses around BooleanNot expressions Oct 18, 2025
-----
<?php

$a = !(a() && b());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fails with

Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '<?php
 
-$a = !(a() && b());'
+$a = !a() && b();'

@nikic
Copy link
Owner

nikic commented Oct 19, 2025

PHP-Parser 5 uses a different way to handle operator precedence in the pretty printer, and it doesn't interact with formatting preservation properly :/

@nikic
Copy link
Owner

nikic commented Oct 19, 2025

This looks pretty tricky. Previously responsibility for printing the parentheses was with the parent node, now it's with the child. Which only works properly if the child is printed without formatting.

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.

2 participants