You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dead catch (catch.neverThrown) false positive around yield $key => $value - a yield with a key loses its implicit throw point #15249
A yield is a point where a generator can be resumed with Generator::throw(), so PHPStan gives every yield an implicit throw point, and a surrounding catch is never reported as dead. That works for yield 1;, but not when the yield has a key. yield 'a' => 1; has no throw point at all:
8: Dead catch - RuntimeException is never thrown in the try block. [catch.neverThrown]
The catch in withKey() is reachable. Running the script prints caught by withKey(). The identical withoutKey() gets no error. The same false positive shows up for yield $k => 1 and $x = yield 'a' => 1. It doesn't show up for yield foo() => 1, because there the key expression brings its own implicit throw point from the function call, which hides the bug.
Cause: src/Analyser/ExprHandler/YieldHandler.php starts $throwPoints with InternalThrowPoint::createImplicit($scope, $expr). When the key is present, line 70 overwrites the array instead of merging into it:
$throwPoints = $keyResult->getThrowPoints();
The value branch just below does it right ($throwPoints = array_merge($throwPoints, $valueResult->getThrowPoints());), and so does the neighbouring $impurePoints line. The key's and the value's throw points are both kept. Only the yield's own implicit throw point is lost. The same $throwPoints also goes into VariableFlowBuilder::throws(), so anything that depends on the yield being a possible throw site (such as variable certainty in the catch block) is affected too.
Activity
phpstan-bot commentedon Sep 17, 2026
Closed via merging phpstan/phpstan-src#6457
github-actions commentedon Oct 19, 2026
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.