Fix missing detection of dead code in closures#4148
Fix missing detection of dead code in closures#4148ondrejmirtes merged 5 commits intophpstan:2.1.xfrom
Conversation
|
@janedbal could you have a look at the shipmonk results of this PR? I had a look at the shipmon/phpstan-rules results, and I think these are correct, as only the 1st callable is immediately invoked - but the tests looks like they expect also the 2nd callable would be immediately invoked..? |
|
@staabm I'm not sure what you mean. The rule denies throwing checked exception in closures unless such closure is passed directly to callable param marked immediately invoked. Thus: /**
* @param-immediately-invoked-callable $callable
*/
public function immediateThrow(
callable $callable, // this callable can be closure with checked exception thrown
?callable $denied = null // this cannot, as we dont know when it will be called, and propagation of such exception cannot be ensured by PHPStan
): voidBut I'm not sure why the test is failing since this MR. I do pass always-terminating closure there as second arg: $this->immediateThrow(
function () {},
function () {
throw new CheckedException(); // rule error, not reported anymore
},
);I believe it should still be reported. I didnt breakpoint it, but it looks like ThrowPoints of the closure might be gone |
|
I think the problem is that immediately throws and therefore all following statements are dead code. |
|
I see, let me adjust the tests there so that we can have it green here. |
…ividual test cases. To support PHPStan's enhanced dead code detection in closures (phpstan/phpstan-src#4148).
|
This pull request has been marked as ready for review. |
|
Thank you. |
followup to #4090
requires #4145