Skip to content

Format-preserving printer loses parentheses around BooleanNot expressions #1119

@maks-rafalko

Description

@maks-rafalko

Environment

Description

When I wrap a BinaryOp\BooleanAnd node in a BooleanNot node, the format-preserving printer loses the required parentheses around the boolean AND expression. This produces semantically incorrect code.

Expected Behavior

The format-preserving printer should add parentheses around the wrapped expression:

$var = !(a() && b());

Actual Behavior

The parentheses are missing, changing the code's meaning:

$var = !a() && b();

Mutation

$stmts[0]->expr->expr = new \PhpParser\Node\Expr\BooleanNot($booleanAnd);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions