Skip to content

Generator suspension points should be treated as infinite loop break points #6189

@SOF3

Description

@SOF3

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/a5262532-e32a-4c45-8340-e96e4931cbda

Expected output

No warnings should be emitted because an infinite loop in a generator is completely fine as long as you don't iterate on it indefinitely. It is just the same as the builtin InfiniteIterator.

This warning should still be emitted if there is an infinite loop that does not contain a yield statement, because there's no way the loop can be broken. But a yield in a loop is effectively a break that just continues when the generator is resumed.

In case anyone is wondering, an infinite loop in a generator does not lead to memory leak (unlike golang goroutines that block forever): https://3v4l.org/Da4Q8 we can see that MustGc is destructed after the generator is no longer used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions