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

Uncaught TypeError: PHPStan\Analyser\MutatingScope::getType() #8072

Closed
gitomato opened this issue Sep 27, 2022 · 5 comments
Closed

Uncaught TypeError: PHPStan\Analyser\MutatingScope::getType() #8072

gitomato opened this issue Sep 27, 2022 · 5 comments

Comments

@gitomato
Copy link

Bug report

Local PHPStan version: 1.8.6

First class callable function with Closures can make PHPStan crash.

Code snippet that reproduces the problem

Here is the smallest snippet I could write to reproduce:
https://phpstan.org/r/af6aa44b-8fff-4f75-ae92-f9f27f3d2f63

Notice the superfluous first class callable.

The PHP script executes normally and produces:

Hi

Expected output

Here is a fixed snippet:
https://phpstan.org/r/18fa015e-7218-49ae-b7a2-9e7acd51f810

The same OK result is expected for previous snippet.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan helps me at each new release and I'm happy to discover how it catches new things in my codebase and improves quality.

@herndlm
Copy link
Contributor

herndlm commented Sep 27, 2022

Seems to be related to Node\Expr\FuncCall::getArgs() asserting that it is not a first class callable. That assertion is not active on e.g. the phpstan web editor. And then it continues execution and instead of Arg[] we get back array{VariadicPlaceholder}. On my dev env the assertion is active and makes it fail earlier.

I could fix it by adapting ArrowFunctionArgVisitor and not calling getArgs() for first class callables, but it looks like this should be done for all PhpParser\Node\Expr\CallLike 🤔

see https://github.com/nikic/PHP-Parser/blob/v4.15.1/lib/PhpParser/Node/Expr/CallLike.php#L36 for the assert and https://github.com/phpstan/phpstan-src/blob/1.8.6/src/Analyser/NodeScopeResolver.php#L3147 for the code that then calls getType with null (VariadicPlaceholder does not have a value prop).

@herndlm
Copy link
Contributor

herndlm commented Sep 29, 2022

I guess I can just patch this in the new visitors/code that was added recently for now to get rid of the problem that was apparently introduced there. Should be able to do this in the evening.
Maybe I'll find a note generic improvement, we'll see. I'll try open a PR anyways.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@3758d9d

@gitomato
Copy link
Author

gitomato commented Oct 3, 2022

Thank you for your reactivity!

@github-actions
Copy link

github-actions bot commented Nov 4, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants