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

Avoid falsely specifying never types via count() #3898

Merged
merged 1 commit into from
Mar 22, 2025

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Mar 22, 2025

Refs #3709 (comment)

The issue was that in a falsey scope with count(array{stdClass}) < int<1, max> it wasn't able to further narrow down the array, and return it as sureNotType, leading to *NEVER* in the end. Hope I'm not inversing the logic too much here.. Then it would try to use never with an array operation, leading to *ERROR* which basically made it then behave like mixed afterwards.

I hate the complex if conditions. This could be somehow more simplified I think, but there are some special cases in the list-count.php test which deals basically with removing arrays from a union of arrays by narrowing via count in both truthy and falsey scopes and I ended up with at least 2 of those not working properly anymore. So this, apparently better, exclusion strategy it is..

Unfortunately "unfixes" phpstan/phpstan#1311, but https://phpstan.org/r/a1ce8144-60c8-43fc-bfac-fcb7086b3a25 shows it was never really properly fixed anyway.

@ondrejmirtes ondrejmirtes merged commit 69db4ae into phpstan:2.1.x Mar 22, 2025
416 of 418 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@herndlm herndlm deleted the count-avoid-never branch March 23, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants