-
Notifications
You must be signed in to change notification settings - Fork 683
feat(analyzer): add HiddenGeneratorReturn
issue
#11459
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
base: 6.x
Are you sure you want to change the base?
Changes from all commits
eb37371
1482be9
2ce149c
59cd9ff
bbf3a93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# HiddenGeneratorReturn | ||
|
||
Emitted when trying to return a value from a generator function that does not have a `Generator` return type. | ||
|
||
```php | ||
<?php | ||
|
||
/** | ||
* @return iterable<"foo"> | ||
*/ | ||
function generator(): iterable | ||
{ | ||
yield "foo"; | ||
|
||
return 1; | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Issue; | ||
|
||
final class HiddenGeneratorReturn extends CodeIssue | ||
{ | ||
public const ERROR_LEVEL = 4; | ||
public const SHORTCODE = 284; | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if those values are correct. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1176,7 +1176,10 @@ function f(array $a): array { | |
'generatorWithUnspecifiedSend' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
/** @return Generator<int,int> */ | ||
/** | ||
* @return Generator<int,int> | ||
* @psalm-suppress MixedReturnStatement | ||
*/ | ||
Comment on lines
+1179
to
+1182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could make sense to not report |
||
function gen() : Generator { | ||
return yield 1; | ||
} | ||
|
@@ -1187,7 +1190,10 @@ function gen() : Generator { | |
'generatorWithMixedSend' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
/** @return Generator<int,int, mixed, mixed> */ | ||
/** | ||
* @return Generator<int,int, mixed, mixed> | ||
* @psalm-suppress MixedReturnStatement | ||
*/ | ||
Comment on lines
+1193
to
+1196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
function gen() : Generator { | ||
return yield 1; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the actual fix for #11458 which replaces the return type being compared against with
TReturn
from a generator, or withmixed
if the current return type is not a generator.