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

Callable parameter loses its argument typing when part of an union type #6629

Closed
axlon opened this issue Feb 10, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1019
Closed

Comments

@axlon
Copy link
Contributor

axlon commented Feb 10, 2022

Bug report

When a function (or method) accepts a callable as part of a union, the type of the callable's parameters seems to get lost.

Code snippet that reproduces the problem

https://phpstan.org/r/7e566448-8b05-4b83-9082-f2169233c862

Expected output

I'd expect the type of the callable's $attributes parameter in the example to be array<string, mixed>, but for some reason PHPStan thinks its mixed. When the union is removed (leaving only the callable), PHPStan reports correctly.

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

PHPStan recently pointed me to a minor issue (when we raised its level) which led me to notice one of our tests was comprised entirely of false positives

@ondrejmirtes
Copy link
Member

This is the piece of code responsible that needs modifying: https://github.com/phpstan/phpstan-src/blob/4f72fdc29eecc12771de3d500a3d336b94c3d685/src/Analyser/NodeScopeResolver.php#L2860-L2868

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Feb 11, 2022
@axlon
Copy link
Contributor Author

axlon commented Feb 11, 2022

Thanks for pointing me in the right direction, will attempt a fix

@github-actions
Copy link

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 Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants