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

Can't check if Iterator is empty #10938

Open
SimonFrings opened this issue Apr 25, 2024 · 1 comment
Open

Can't check if Iterator is empty #10938

SimonFrings opened this issue Apr 25, 2024 · 1 comment

Comments

@SimonFrings
Copy link

SimonFrings commented Apr 25, 2024

Bug report

Hey there, I'm working on ReactPHP and it seems we can't really check if an Iterator is empty or not. We could really use this for our Promise and Async component, happy about your insights on this.

Code snippet that reproduces the problem

https://phpstan.org/r/fac73ffc-131a-43d1-8cb7-b1a629374ac1

Expected output

I think PHPStan should detect that the Iterator is empty here.

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

PHPStan always makes me happy

@ondrejmirtes
Copy link
Member

The typesystem cannot express anything like non-empty-Iterator right now. You can do something like this to make your code sample pass but it's not very useful in practice: https://phpstan.org/r/d34a8454-8a5c-4971-9a02-f28508718f89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants