Skip to content

Commit 9d97d49

Browse files
committed
Fix crash on MethodCallableNode on do while
1 parent 46b9819 commit 9d97d49

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/Node/Printer/ExprPrinter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Node\Printer;
44

55
use PhpParser\Node\Expr;
6+
use PHPStan\Node\MethodCallableNode;
67

78
/**
89
* @api
@@ -19,6 +20,9 @@ public function printExpr(Expr $expr): string
1920
/** @var string|null $exprString */
2021
$exprString = $expr->getAttribute('phpstan_cache_printer');
2122
if ($exprString === null) {
23+
if ($expr instanceof MethodCallableNode) {
24+
$expr = $expr->getOriginalNode();
25+
}
2226
$exprString = $this->printer->prettyPrintExpr($expr);
2327
$expr->setAttribute('phpstan_cache_printer', $exprString);
2428
}

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,4 +3491,14 @@ public function testBug4801(): void
34913491
$this->analyse([__DIR__ . '/data/bug-4801.php'], []);
34923492
}
34933493

3494+
public function testBug12246(): void
3495+
{
3496+
$this->checkThisOnly = false;
3497+
$this->checkNullables = false;
3498+
$this->checkUnionTypes = false;
3499+
$this->checkExplicitMixed = false;
3500+
3501+
$this->analyse([ __DIR__ . '/data/first_class_callable_do_while.php'], []);
3502+
}
3503+
34943504
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace FirstClassCallableInDoWhile;
4+
5+
final class SomeFirstClassCallableInDoWhile
6+
{
7+
public function getSubscribedEvents()
8+
{
9+
do {
10+
11+
} while ($this->textElement(...));
12+
}
13+
14+
public function textElement()
15+
{
16+
return 1;
17+
}
18+
}

0 commit comments

Comments
 (0)