Skip to content

Commit

Permalink
fix fn() => __FUNCTION__ and __METHOD__
Browse files Browse the repository at this point in the history
  • Loading branch information
schlndh authored and ondrejmirtes committed Feb 23, 2024
1 parent a06d509 commit 58ebacf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,7 @@ private function enterArrowFunctionWithoutReflection(Expr\ArrowFunction $arrowFu
$arrowFunctionScope->nativeExpressionTypes,
$arrowFunctionScope->conditionalExpressions,
$arrowFunctionScope->inClosureBindScopeClasses,
null,
new TrivialParametersAcceptor(),
true,
[],
[],
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ public function dataFileAsserts(): iterable

if (PHP_VERSION_ID >= 70400) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/arrow-function-argument-type.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-anonymous-function-method-constant.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-argument-type.php');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ public function testBugSpaceship(): void
$this->analyse([__DIR__ . '/data/bug-spaceship.php'], []);
}

public function testBugFunctionMethodConstants(): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []);
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

/**
* @extends RuleTestCase<ClosureReturnTypeRule>
Expand Down Expand Up @@ -128,4 +129,13 @@ public function testBug7220(): void
$this->analyse([__DIR__ . '/data/bug-7220.php'], []);
}

public function testBugFunctionMethodConstants(): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types = 1); // lint >= 7.4

namespace BugAnonymousFunctionMethodConstant;

$a = fn() => __FUNCTION__;
$b = fn() => __METHOD__;

$c = function() { return __FUNCTION__; };
$d = function() { return __METHOD__; };

\PHPStan\Testing\assertType("'{closure}'", $a());
\PHPStan\Testing\assertType("'{closure}'", $b());
\PHPStan\Testing\assertType("'{closure}'", $c());
\PHPStan\Testing\assertType("'{closure}'", $d());

0 comments on commit 58ebacf

Please sign in to comment.