Skip to content

Commit 61f7a97

Browse files
committed
Function with yield from wasn't recognized as generator
1 parent a3e644a commit 61f7a97

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"nette/utils": "^3.1.1",
2222
"nikic/php-parser": "^4.5.0",
2323
"ondram/ci-detector": "^3.1",
24-
"ondrejmirtes/better-reflection": "^4.3.2",
24+
"ondrejmirtes/better-reflection": "^4.3.3",
2525
"phpdocumentor/type-resolver": "1.0.1",
2626
"phpstan/phpdoc-parser": "^0.4.7",
2727
"react/child-process": "^0.6.1",

tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,13 @@ public function testReturnTypeRulePhp70(): void
7070
]);
7171
}
7272

73+
public function testIsGenerator(): void
74+
{
75+
if (!self::$useStaticReflectionProvider) {
76+
$this->markTestSkipped('Test requires static reflection.');
77+
}
78+
79+
$this->analyse([__DIR__ . '/data/is-generator.php'], []);
80+
}
81+
7382
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace FunctionGeneratorReturn;
4+
5+
class Foo
6+
{
7+
8+
}
9+
10+
if (false) {
11+
function doBar(bool $skipThings): iterable
12+
{
13+
if ($skipThings) {
14+
return;
15+
}
16+
17+
yield 1;
18+
}
19+
20+
function doFoo(bool $skipThings): iterable
21+
{
22+
if ($skipThings) {
23+
return;
24+
}
25+
26+
yield from array();
27+
}
28+
}

0 commit comments

Comments
 (0)