Skip to content

Commit

Permalink
Fix potential assert failures - use getRawArgs() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 29, 2022
1 parent 37c643c commit 6cd3d5d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Parser/ArrayFilterArgVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function enterNode(Node $node): ?Node
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
$functionName = $node->name->toLowerString();
if ($functionName === 'array_filter') {
$args = $node->getArgs();
$args = $node->getRawArgs();
if (isset($args[0])) {
$args[0]->setAttribute(self::ATTRIBUTE_NAME, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ArrayMapArgVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ArrayMapArgVisitor extends NodeVisitorAbstract

public function enterNode(Node $node): ?Node
{
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && !$node->isFirstClassCallable()) {
$functionName = $node->name->toLowerString();
if ($functionName === 'array_map') {
$args = $node->getArgs();
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ArrayWalkArgVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function enterNode(Node $node): ?Node
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
$functionName = $node->name->toLowerString();
if ($functionName === 'array_walk') {
$args = $node->getArgs();
$args = $node->getRawArgs();
if (isset($args[0])) {
$args[0]->setAttribute(self::ATTRIBUTE_NAME, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ArrowFunctionArgVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ArrowFunctionArgVisitor extends NodeVisitorAbstract
public function enterNode(Node $node): ?Node
{
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Expr\ArrowFunction) {
$args = $node->getArgs();
$args = $node->getRawArgs();

if (count($args) > 0) {
$node->name->setAttribute(self::ATTRIBUTE_NAME, $args);
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ClosureArgVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ClosureArgVisitor extends NodeVisitorAbstract
public function enterNode(Node $node): ?Node
{
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Expr\Closure) {
$args = $node->getArgs();
$args = $node->getRawArgs();

if (count($args) > 0) {
$node->name->setAttribute(self::ATTRIBUTE_NAME, $args);
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/CurlSetOptArgVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function enterNode(Node $node): ?Node
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
$functionName = $node->name->toLowerString();
if ($functionName === 'curl_setopt') {
$args = $node->getArgs();
$args = $node->getRawArgs();
if (isset($args[0])) {
$args[0]->setAttribute(self::ATTRIBUTE_NAME, true);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,12 @@ public function testBug7963Two(): void
$this->assertNoErrors($errors);
}

public function testBug8078(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-8078.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8078.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php // lint >= 8.1

namespace Bug8078;

class HelloWorld
{
public function test(): void
{
$closure = (static fn (): string => 'evaluated Closure')(...);
}
}

0 comments on commit 6cd3d5d

Please sign in to comment.