Skip to content

Commit

Permalink
Fix empty list insertion of multiple attributes
Browse files Browse the repository at this point in the history
(cherry picked from commit 44c6a97)
  • Loading branch information
nikic committed Sep 4, 2022
1 parent 617d022 commit 8216e87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/PhpParser/PrettyPrinterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,9 @@ protected function pArray(
foreach ($delayedAdd as $delayedAddNode) {
if (!$first) {
$result .= $insertStr;
if ($insertNewline) {
$result .= $this->nl;
}
}
$result .= $this->p($delayedAddNode, true);
$first = false;
Expand Down
7 changes: 7 additions & 0 deletions test/code/formatPreservation/attributes.test
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ fn()
$attrGroup = new Node\AttributeGroup([
new Node\Attribute(new Node\Name('A'), []),
]);
$attrGroup2 = new Node\AttributeGroup([
new Node\Attribute(new Node\Name('B'), []),
]);
$stmts[0]->attrGroups[] = $attrGroup;
$stmts[0]->attrGroups[] = $attrGroup2;
$stmts[0]->stmts[0]->attrGroups[] = $attrGroup;
$stmts[0]->stmts[0]->attrGroups[] = $attrGroup2;
$stmts[0]->stmts[1]->attrGroups[] = $attrGroup;
$stmts[0]->stmts[2]->attrGroups[] = $attrGroup;
$stmts[1]->attrGroups[] = $attrGroup;
Expand All @@ -118,8 +123,10 @@ $stmts[6]->expr->attrGroups[] = $attrGroup;
-----
<?php
#[A]
#[B]
class X {
#[A]
#[B]
public function m() {}

#[A]
Expand Down

0 comments on commit 8216e87

Please sign in to comment.