Skip to content

Commit

Permalink
Function with yield from wasn't recognized as generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 8, 2020
1 parent a3e644a commit 61f7a97
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nette/utils": "^3.1.1",
"nikic/php-parser": "^4.5.0",
"ondram/ci-detector": "^3.1",
"ondrejmirtes/better-reflection": "^4.3.2",
"ondrejmirtes/better-reflection": "^4.3.3",
"phpdocumentor/type-resolver": "1.0.1",
"phpstan/phpdoc-parser": "^0.4.7",
"react/child-process": "^0.6.1",
Expand Down
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ public function testReturnTypeRulePhp70(): void
]);
}

public function testIsGenerator(): void
{
if (!self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires static reflection.');
}

$this->analyse([__DIR__ . '/data/is-generator.php'], []);
}

}
28 changes: 28 additions & 0 deletions tests/PHPStan/Rules/Functions/data/is-generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace FunctionGeneratorReturn;

class Foo
{

}

if (false) {
function doBar(bool $skipThings): iterable
{
if ($skipThings) {
return;
}

yield 1;
}

function doFoo(bool $skipThings): iterable
{
if ($skipThings) {
return;
}

yield from array();
}
}

0 comments on commit 61f7a97

Please sign in to comment.