|
18 | 18 | use PhpParser\Node\Expr\BinaryOp\Pipe; |
19 | 19 | use PhpParser\Node\Expr\CallLike; |
20 | 20 | use PhpParser\Node\Expr\Instanceof_; |
| 21 | +use PhpParser\Node\Expr\Match_; |
21 | 22 | use PhpParser\Node\Expr\MethodCall; |
22 | 23 | use PhpParser\Node\Expr\Ternary; |
23 | 24 | use PhpParser\Node\Expr\Yield_; |
|
29 | 30 | use PhpParser\Node\Stmt\Nop; |
30 | 31 | use PhpParser\PrettyPrinter\Standard; |
31 | 32 | use PhpParser\Token; |
| 33 | +use PHPStan\Node\Expr\AlwaysRememberedExpr; |
32 | 34 | use Rector\Configuration\Option; |
33 | 35 | use Rector\Configuration\Parameter\SimpleParameterProvider; |
34 | 36 | use Rector\NodeAnalyzer\ExprAnalyzer; |
@@ -125,6 +127,23 @@ protected function p( |
125 | 127 | int $lhsPrecedence = self::MAX_PRECEDENCE, |
126 | 128 | bool $parentFormatPreserved = false |
127 | 129 | ): string { |
| 130 | + // handle already AlwaysRememberedExpr |
| 131 | + // @see https://github.com/rectorphp/rector/issues/8815#issuecomment-2503453191 |
| 132 | + if ($node instanceof AlwaysRememberedExpr) { |
| 133 | + return $this->p($node->getExpr(), $precedence, $lhsPrecedence, $parentFormatPreserved); |
| 134 | + } |
| 135 | + |
| 136 | + // handle overlapped origNode is Match_ and its subnodes still have AlwaysRememberedExpr |
| 137 | + $originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE); |
| 138 | + if ($originalNode instanceof Match_) { |
| 139 | + $subNodeNames = $node->getSubNodeNames(); |
| 140 | + foreach ($subNodeNames as $subNodeName) { |
| 141 | + while ($originalNode->{$subNodeName} instanceof AlwaysRememberedExpr) { |
| 142 | + $originalNode->{$subNodeName} = $originalNode->{$subNodeName}->getExpr(); |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | + |
128 | 147 | $this->wrapBinaryOpWithBrackets($node); |
129 | 148 |
|
130 | 149 | $content = parent::p($node, $precedence, $lhsPrecedence, $parentFormatPreserved); |
|
0 commit comments