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

Inline yield in Generator complains about missing return type #3669

Closed
dantleech opened this issue Jul 24, 2020 · 2 comments
Closed

Inline yield in Generator complains about missing return type #3669

dantleech opened this issue Jul 24, 2020 · 2 comments
Labels
Milestone

Comments

@dantleech
Copy link

dantleech commented Jul 24, 2020

PHPStan reports a false positive when inline yield is used:

<?php

function foo(): Generator
{
    while ($bar = yield 'foo') {
    }
}
Function foo() should return Generator but return statement is missing.

https://phpstan.org/r/ec37ffcb-25f5-424a-b21c-2f5ec10703dd

@ondrejmirtes
Copy link
Member

This one is really easy to fix. We have to also take into account $condResult->hasYield() here https://github.com/phpstan/phpstan-src/blob/a23f80828620e663c67bbacdcb246b888db158a4/src/Analyser/NodeScopeResolver.php#L809, not just $finalScopeResult->hasYield() at https://github.com/phpstan/phpstan-src/blob/a23f80828620e663c67bbacdcb246b888db158a4/src/Analyser/NodeScopeResolver.php#L870.

The best way to test this is to add another test to Functions ReturnTypeRuleTest.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants