Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix crash on MethodCallableNode on do while #3752

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

Open
samsonasik wants to merge 1 commit into phpstan:2.1.x
base: 2.1.x
Choose a base branch
Loading
from samsonasik:fix-crash-method-callable-node
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
Fix crash on MethodCallableNode on do while
  • Loading branch information
samsonasik committed Dec 22, 2024
commit 9d97d4950cd293648e51d843ca0721e6ff6aba1f
4 changes: 4 additions & 0 deletions src/Node/Printer/ExprPrinter.php
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /