-
Notifications
You must be signed in to change notification settings - Fork 546
FNSR false positive: Call to method X on a separate line has no effect #4738
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
base: 2.1.x
Are you sure you want to change the base?
Conversation
|
I think the bug does not reproduce in tests (but it does when running the repro script standalone), because in tests a method is filtered out because it is reported to have impure point, while it doesn't have a impure point when running standalone phpstan-src/src/Rules/DeadCode/MethodWithoutImpurePointsCollector.php Lines 34 to 36 in a951ac0
|
|
applying this diff makes the test fail, with the same error we get when run standalone: diff --git a/src/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRule.php b/src/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRule.php
index a04d151ad9..65d63f8d29 100644
--- a/src/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRule.php
+++ b/src/Rules/DeadCode/CallToMethodStatementWithoutImpurePointsRule.php
@@ -34,6 +34,11 @@ final class CallToMethodStatementWithoutImpurePointsRule implements Rule
}
}
+ $methods['bug13956\foo'] = [
+ 'addsuccess' => 'Bug13956\Foo::addSuccess',
+ 'getsuccessmessages' => 'Bug13956\Foo::getSuccessMessages',
+ ];
+
$errors = [];
foreach ($node->get(PossiblyPureMethodCallCollector::class) as $filePath => $data) {
foreach ($data as [$classNames, $method, $line]) { |
|
interessting.. I can see that in
a impure point is generated and appended to the by-ref array
I can see the array is still empty. so I suspect either xdebug is lying/buggy or php-src somehow looses the by-ref appended array content. |
|
Fibers are not threads, they still work with the same objects and values, they are just "functions that can be paused and resumed later". I'll look into it later, but caching of FileTypeMapper and releasing the current performance improvements is a priority 😊 |
|
Alright, with this diff: diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php
index 043ae8943c..0ae6a24889 100644
--- a/src/Analyser/NodeScopeResolver.php
+++ b/src/Analyser/NodeScopeResolver.php
@@ -798,7 +798,8 @@ class NodeScopeResolver
$gatheredYieldStatements = [];
$executionEnds = [];
$methodImpurePoints = [];
- $statementResult = $this->processStmtNodesInternal($stmt, $stmt->stmts, $methodScope, $storage, static function (Node $node, Scope $scope) use ($nodeCallback, $methodScope, &$gatheredReturnStatements, &$gatheredYieldStatements, &$executionEnds, &$methodImpurePoints): void {
+ $a = md5(uniqid());
+ $statementResult = $this->processStmtNodesInternal($stmt, $stmt->stmts, $methodScope, $storage, static function (Node $node, Scope $scope) use ($nodeCallback, $a, $methodScope, &$gatheredReturnStatements, &$gatheredYieldStatements, &$executionEnds, &$methodImpurePoints): void {
$nodeCallback($node, $scope);
if ($scope->getFunction() !== $methodScope->getFunction()) {
return;
@@ -816,6 +817,8 @@ class NodeScopeResolver
) {
return;
}
+ var_dump('add:');
+ var_dump($a);
$methodImpurePoints[] = new ImpurePoint(
$scope,
$node,
@@ -823,6 +826,7 @@ class NodeScopeResolver
'property assignment',
true,
);
+ var_dump('------');
return;
}
if ($node instanceof ExecutionEndNode) {
@@ -839,6 +843,11 @@ class NodeScopeResolver
$gatheredReturnStatements[] = new ReturnStatement($scope, $node);
}, StatementContext::createTopLevel())->toPublic();
+ var_dump('below:');
+ var_dump($a);
+ var_dump(count($methodImpurePoints));
+ var_dump('------');
+
$methodReflection = $methodScope->getFunction();
if (!$methodReflection instanceof PhpMethodFromParserNodeReflection) {
throw new ShouldNotHappenException();
I figured out why it breaks with full analysis and not in test of a single rule. The output is this: So the callback is "paused" in a Fiber and the rest of the analysis continues. I'm surprised that more stuff doesn't break because of this. I'll have to think about what we can do about it. |
|
Here's a quick fix but it's stupid: 60c3118 |


closes phpstan/phpstan#13956