-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
[BUG] "Method…should return Generator but returns false" #574
Labels
Milestone
Comments
I don't understand, what is a real-world usecase for this? |
For example coroutines, see https://github.com/recoilphp/recoil/#returning-a-value-from-a-coroutine |
OK, my proposed fix is:
|
Implemented first part: 5b940d5 |
More examples: https://phpstan.org/r/da276b35474dead2cfa290e8d6b96ff1 function f() : Generator {
yield 1;
yield 2;
return "hello";
}
function g() : Generator {
if (rand(0, 1)) {
return;
}
if (rand(0, 1)) {
yield 1;
}
return "goodbye";
}
$f = f();
$g = g();
foreach ($f as $i) {
var_dump($i);
}
var_dump($f->getReturn());
foreach ($g as $j) {
var_dump($j);
}
var_dump($g->getReturn()); |
But the second option here should fail as in https://getpsalm.org/r/0ef6ef4478 function generator2() : Generator {
if (rand(0,1)) {
return;
}
yield 2;
}
function notagenerator() : Generator {
if (rand(0,1)) {
return;
}
return generator2();
} |
This already works, thanks. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
This is a false positive, because returning
false
from a method whichyield
s still returns aGenerator
, see:Output:
See also https://3v4l.org/VcSpa
The text was updated successfully, but these errors were encountered: