Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on MethodCallableNode on do while #3752

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading