Skip to content
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

analyzing code with unknown symbols triggers internal errors #268

Closed
staabm opened this issue Sep 18, 2024 · 2 comments · Fixed by #273
Closed

analyzing code with unknown symbols triggers internal errors #268

staabm opened this issue Sep 18, 2024 · 2 comments · Fixed by #273

Comments

@staabm
Copy link

staabm commented Sep 18, 2024

analyze a file like

<?php

namespace X;

class A {
    public function aMethod():bool {
        return true;
    }
}

function doFoo() {
    /** @var A $x */
    $x = createMagically();
    $x->aMethod();
}

triggers this exception

$ php vendor/bin/phpstan analyze test.php --debug -v
Note: Using configuration file C:\dvl\Workspace\dead-code-detector\phpstan.neon.dist.
C:\dvl\Workspace\dead-code-detector\test.php
 -- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
     Error
 -- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
     Internal error: Function createMagically not found while trying to analyse it - discovering symbols is probably not configured properly. while analysing file
     C:\dvl\Workspace\dead-code-detector\test.php
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:
     ## phar://C:/dvl/Workspace/dead-code-detector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php(247)
     #0 phar://C:/dvl/Workspace/dead-code-detector/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(67):
     PHPStan\Reflection\BetterReflection\BetterReflectionProvider->getFunction()
     shipmonk-rnd/dead-code-detector#1 C:\dvl\Workspace\dead-code-detector\vendor\shipmonk\phpstan-rules\src\Rule\ForbidCheckedExceptionInCallableRule.php(430):
     PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->getFunction()
     shipmonk-rnd/dead-code-detector#2 C:\dvl\Workspace\dead-code-detector\vendor\shipmonk\phpstan-rules\src\Rule\ForbidCheckedExceptionInCallableRule.php(123):
     ShipMonk\PHPStan\Rule\ForbidCheckedExceptionInCallableRule->whitelistAllowedCallables()
     shipmonk-rnd/dead-code-detector#3 phar://C:/dvl/Workspace/dead-code-detector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(120):
     ShipMonk\PHPStan\Rule\ForbidCheckedExceptionInCallableRule->processNode()
     shipmonk-rnd/dead-code-detector#4 phar://C:/dvl/Workspace/dead-code-detector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(583):
     PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()
     shipmonk-rnd/dead-code-detector#5 phar://C:/dvl/Workspace/dead-code-detector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(728):
     PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}()
     shipmonk-rnd/dead-code-detector#6 phar://C:/dvl/Workspace/dead-code-detector/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(3237):
     PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}()

because ForbidCheckedExceptionInCallableRule calls $this->reflectionProvider->getFunction without a previous $this->reflectionProvider->hasFunction.

I guess similar things are possible with MethodCall, StaticCall etc.

root-cause of the problem is in shipmonk/phpstan-rules

@janedbal janedbal transferred this issue from shipmonk-rnd/dead-code-detector Sep 26, 2024
@janedbal
Copy link
Member

Issue transferred, I'll take a look once I return from vacation.

Thanks

@janedbal
Copy link
Member

janedbal commented Oct 1, 2024

Fixed in latest 3.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants