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

Expand unpacked constant array parameter when checking function call #3481

Closed
ondrejmirtes opened this issue Jun 16, 2020 · 8 comments
Closed
Labels
Milestone

Comments

@ondrejmirtes
Copy link
Member

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/3499bb45-63b7-45e6-96ce-4b00b094c553

Expected output

No errors

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jun 16, 2020
@ondrejmirtes
Copy link
Member Author

Fixed: phpstan/phpstan-src@a21012d

@soukicz
Copy link

soukicz commented Jul 1, 2020

https://phpstan.org/r/7bade35e-c6ba-4f23-918a-3b16aef57f0b

This change is now reporting false positives. It works if it knows for sure how many elements are in array but it is reporting error if the array is created with conditions.

@ondrejmirtes
Copy link
Member Author

@soukicz I don't think it's a false positive. it can happen that your array is empty, and that throws an exception: https://3v4l.org/NnEhZ

@soukicz
Copy link

soukicz commented Jul 1, 2020

Damn... I didn't realize that my count condition doesn't handle empty array (because it cannot happen in real use case)

@ondrejmirtes
Copy link
Member Author

So is PHPStan correct here, or do you have a better example that shows a false positive? :)

@soukicz
Copy link

soukicz commented Jul 1, 2020

Here is updated example that shouldn't report error: https://phpstan.org/r/17472a8a-39d9-4542-85fd-2e0772ba5ba9

EDIT: updated to even more specific condition

@ondrejmirtes
Copy link
Member Author

Tracked as: #3558

@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 May 16, 2021
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

2 participants