diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php index 34c2e27ba..dc540335a 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php @@ -343,7 +343,8 @@ class ReturnTypeCollector if ($stmt instanceof PhpParser\Node\Expr\MethodCall || $stmt instanceof PhpParser\Node\Expr\FuncCall - || $stmt instanceof PhpParser\Node\Expr\StaticCall) { + || $stmt instanceof PhpParser\Node\Expr\StaticCall + || $stmt instanceof PhpParser\Node\Expr\New_) { $yield_types = []; foreach ($stmt->getArgs() as $arg) { diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index 8feb6988b..d32a48374 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -286,6 +286,15 @@ class GeneratorTest extends TestCase '$iterator' => 'NoRewindIterator', ] ], + 'detectYieldInNew' => [ + ' [ + '$_a' => 'pure-Closure():Generator', + ] + ], ]; }