Skip to content

Anonymous function should return iterable but empty return statement found. #3891

@gnutix

Description

@gnutix

Bug report

Using the return type iterable for an anonymous function that uses yield and return; statements (to avoid nesting conditions) will result in a PhpStan error, while changing the return type to \Generator works (yet the behavior is exactly the same - even if there's nothing yielded).

Code snippet that reproduces the problem

https://phpstan.org/r/543d5516-5eda-49f9-adc6-23e882e4a489

Expected output

No errors, just as in this example using \Generator instead : https://phpstan.org/r/f7ddaba0-4248-4bbf-b4de-22cfa1a2d819

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions