Skip to content

Commit

Permalink
Fix crash on MethodCallableNode on do while
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 22, 2024
1 parent 46b9819 commit 9d97d49
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Node/Printer/ExprPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPStan\Node\Printer;

use PhpParser\Node\Expr;
use PHPStan\Node\MethodCallableNode;

/**
* @api
Expand All @@ -19,6 +20,9 @@ public function printExpr(Expr $expr): string
/** @var string|null $exprString */
$exprString = $expr->getAttribute('phpstan_cache_printer');
if ($exprString === null) {
if ($expr instanceof MethodCallableNode) {
$expr = $expr->getOriginalNode();
}
$exprString = $this->printer->prettyPrintExpr($expr);
$expr->setAttribute('phpstan_cache_printer', $exprString);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3491,4 +3491,14 @@ public function testBug4801(): void
$this->analyse([__DIR__ . '/data/bug-4801.php'], []);
}

public function testBug12246(): void
{
$this->checkThisOnly = false;
$this->checkNullables = false;
$this->checkUnionTypes = false;
$this->checkExplicitMixed = false;

$this->analyse([ __DIR__ . '/data/first_class_callable_do_while.php'], []);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Methods/data/first_class_callable_do_while.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace FirstClassCallableInDoWhile;

final class SomeFirstClassCallableInDoWhile
{
public function getSubscribedEvents()
{
do {

} while ($this->textElement(...));
}

public function textElement()
{
return 1;
}
}

0 comments on commit 9d97d49

Please sign in to comment.