Skip to content

Commit 6cd3d5d

Browse files
committed
Fix potential assert failures - use getRawArgs() instead
1 parent 37c643c commit 6cd3d5d

8 files changed

Lines changed: 23 additions & 6 deletions

src/Parser/ArrayFilterArgVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function enterNode(Node $node): ?Node
1515
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
1616
$functionName = $node->name->toLowerString();
1717
if ($functionName === 'array_filter') {
18-
$args = $node->getArgs();
18+
$args = $node->getRawArgs();
1919
if (isset($args[0])) {
2020
$args[0]->setAttribute(self::ATTRIBUTE_NAME, true);
2121
}

src/Parser/ArrayMapArgVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ArrayMapArgVisitor extends NodeVisitorAbstract
1414

1515
public function enterNode(Node $node): ?Node
1616
{
17-
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
17+
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && !$node->isFirstClassCallable()) {
1818
$functionName = $node->name->toLowerString();
1919
if ($functionName === 'array_map') {
2020
$args = $node->getArgs();

src/Parser/ArrayWalkArgVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function enterNode(Node $node): ?Node
1515
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
1616
$functionName = $node->name->toLowerString();
1717
if ($functionName === 'array_walk') {
18-
$args = $node->getArgs();
18+
$args = $node->getRawArgs();
1919
if (isset($args[0])) {
2020
$args[0]->setAttribute(self::ATTRIBUTE_NAME, true);
2121
}

src/Parser/ArrowFunctionArgVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ArrowFunctionArgVisitor extends NodeVisitorAbstract
1414
public function enterNode(Node $node): ?Node
1515
{
1616
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Expr\ArrowFunction) {
17-
$args = $node->getArgs();
17+
$args = $node->getRawArgs();
1818

1919
if (count($args) > 0) {
2020
$node->name->setAttribute(self::ATTRIBUTE_NAME, $args);

src/Parser/ClosureArgVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ClosureArgVisitor extends NodeVisitorAbstract
1414
public function enterNode(Node $node): ?Node
1515
{
1616
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Expr\Closure) {
17-
$args = $node->getArgs();
17+
$args = $node->getRawArgs();
1818

1919
if (count($args) > 0) {
2020
$node->name->setAttribute(self::ATTRIBUTE_NAME, $args);

src/Parser/CurlSetOptArgVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function enterNode(Node $node): ?Node
1515
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
1616
$functionName = $node->name->toLowerString();
1717
if ($functionName === 'curl_setopt') {
18-
$args = $node->getArgs();
18+
$args = $node->getRawArgs();
1919
if (isset($args[0])) {
2020
$args[0]->setAttribute(self::ATTRIBUTE_NAME, true);
2121
}

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,12 @@ public function testBug7963Two(): void
982982
$this->assertNoErrors($errors);
983983
}
984984

985+
public function testBug8078(): void
986+
{
987+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-8078.php');
988+
$this->assertNoErrors($errors);
989+
}
990+
985991
/**
986992
* @param string[]|null $allAnalysedFiles
987993
* @return Error[]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug8078;
4+
5+
class HelloWorld
6+
{
7+
public function test(): void
8+
{
9+
$closure = (static fn (): string => 'evaluated Closure')(...);
10+
}
11+
}

0 commit comments

Comments
 (0)