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

Generator send type is not checked when traversing it with foreach #6985

Closed
weirdan opened this issue Nov 24, 2021 · 1 comment · Fixed by #10697
Closed

Generator send type is not checked when traversing it with foreach #6985

weirdan opened this issue Nov 24, 2021 · 1 comment · Fixed by #10697

Comments

@weirdan
Copy link
Collaborator

weirdan commented Nov 24, 2021

https://psalm.dev/r/11773a3883

I'd expect something along the lines of Cannot iterate over a generator with non-nullable send() parameter type.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/11773a3883
<?php
/** @return Generator<int, int, string, string> */
function f(): Generator {
    return yield 1;
}
$i = f();

// the following iteration should be flagged, 
// as `foreach` calls `next()` and it's the same as calling `send(null)`
foreach ($i as $_k => $_v);

$i->send(null); // this is correctly flagged
Psalm output (using commit b4d25cb):

ERROR: NullArgument - 12:10 - Argument 1 of Generator::send cannot be null, null value provided to parameter with type string

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

Successfully merging a pull request may close this issue.

2 participants