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

FP: Switch(count(array)) doesn't infer non-empty-array when case is 1 or more #4499

Closed
dktapps opened this issue Feb 6, 2021 · 6 comments
Closed

Comments

@dktapps
Copy link
Contributor

dktapps commented Feb 6, 2021

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/30604226-e6f3-459e-947c-95a807f7c064

Expected output

The dumped type should be int, not int|null, because the number of items is known to be non-zero.

@ondrejmirtes
Copy link
Member

PHPStan mostly doesn't support == semantics: https://phpstan.org/r/bddd3456-2792-4083-bca4-447a09570b72

Works with match: https://phpstan.org/r/3a040f9a-463b-4708-a6fb-bc3f7d0adc94

@dktapps
Copy link
Contributor Author

dktapps commented Feb 6, 2021

Thanks. match isn't currently an option for me because I haven't moved to 8.0 exclusively yet, so I've just ignored it for now.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-7: Dumped type: int|null
+7: Dumped type: int
Full report
Line Error
7 Dumped type: int

@phpstan-bot
Copy link
Contributor

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

@@ @@
-6: Dumped type: int|null
+6: Dumped type: int
Full report
Line Error
6 Dumped type: int

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src#648

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

No branches or pull requests

3 participants