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

Nullable mixed array does not match string array when unpacking function result #6423

Closed
ndench opened this issue Jan 20, 2022 · 3 comments
Closed
Labels
Milestone

Comments

@ndench
Copy link
Contributor

ndench commented Jan 20, 2022

Bug report

This seems like a crazy edge case. I have a function that takes a nullable mixed array. When I call this function and pass in a list that's built using the unpacked result of a function, I get an error:

function foo expects array<int, mixed>|null, array<int, string> given.

Code snippet that reproduces the problem

Here is the error:
https://phpstan.org/r/d2c5bf08-d6bf-4888-ab7c-9a1db035688b

The error disappears when the function parameter is not nullable.
https://phpstan.org/r/db2aa007-c7e2-484d-9ddc-3e336f2ac91d

The error also disappears when we do not unpack the result of another function.
https://phpstan.org/r/4fe5bcde-068f-4767-996e-46eba8af5f00

Expected output

I expect this to produce no errors.

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

PHPStan speeds up my code reviews!

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jan 20, 2022
@phpstan-bot
Copy link
Contributor

@ndench After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-19: Parameter #1 $foos of function foo expects array<int, mixed>|null, array<int, string> given.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@9f12f0f

ondrejmirtes added a commit to phpstan/phpstan-src that referenced this issue Feb 28, 2022
@github-actions
Copy link

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

No branches or pull requests

3 participants