diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index f2ce6e9c2e..0d2b425fb8 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -1638,6 +1638,16 @@ private function processStmtNode( } else { $catchScope = $catchScope->mergeWith($matchingThrowPoint->getScope()); } + + foreach ($finallyExitPoints as $key => $finallyExitPoint) { + if ( + $finallyExitPoint->getStatement() instanceof Node\Stmt\Expression + && $finallyExitPoint->getStatement()->expr === $matchingThrowPoint->getNode() + ) { + unset($finallyExitPoints[$key]); + break; + } + } } $variableName = null; diff --git a/tests/PHPStan/Rules/Exceptions/OverwrittenExitPointByFinallyRuleTest.php b/tests/PHPStan/Rules/Exceptions/OverwrittenExitPointByFinallyRuleTest.php index 1698ada07c..6fff563d78 100644 --- a/tests/PHPStan/Rules/Exceptions/OverwrittenExitPointByFinallyRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/OverwrittenExitPointByFinallyRuleTest.php @@ -19,10 +19,6 @@ protected function getRule(): Rule public function testRule(): void { $this->analyse([__DIR__ . '/data/overwritten-exit-point.php'], [ - [ - 'This throw is overwritten by a different one in the finally block below.', - 8, - ], [ 'This return is overwritten by a different one in the finally block below.', 11, @@ -41,10 +37,6 @@ public function testRule(): void public function testBug5627(): void { $this->analyse([__DIR__ . '/data/bug-5627.php'], [ - [ - 'This throw is overwritten by a different one in the finally block below.', - 10, - ], [ 'This throw is overwritten by a different one in the finally block below.', 12, @@ -53,10 +45,6 @@ public function testBug5627(): void 'The overwriting return is on this line.', 14, ], - [ - 'This exit point is overwritten by a different one in the finally block below.', - 29, - ], [ 'This exit point is overwritten by a different one in the finally block below.', 31, @@ -65,10 +53,6 @@ public function testBug5627(): void 'The overwriting return is on this line.', 33, ], - [ - 'This exit point is overwritten by a different one in the finally block below.', - 39, - ], [ 'This exit point is overwritten by a different one in the finally block below.', 41, @@ -85,10 +69,6 @@ public function testBug5627(): void 'The overwriting return is on this line.', 51, ], - [ - 'This throw is overwritten by a different one in the finally block below.', - 62, - ], [ 'This throw is overwritten by a different one in the finally block below.', 64, @@ -97,10 +77,6 @@ public function testBug5627(): void 'The overwriting return is on this line.', 66, ], - [ - 'This exit point is overwritten by a different one in the finally block below.', - 81, - ], [ 'This exit point is overwritten by a different one in the finally block below.', 83, @@ -109,10 +85,6 @@ public function testBug5627(): void 'The overwriting return is on this line.', 85, ], - [ - 'This exit point is overwritten by a different one in the finally block below.', - 91, - ], [ 'This exit point is overwritten by a different one in the finally block below.', 93, @@ -129,10 +101,6 @@ public function testBug5627(): void 'The overwriting return is on this line.', 103, ], - [ - 'This throw is overwritten by a different one in the finally block below.', - 122, - ], [ 'This throw is overwritten by a different one in the finally block below.', 124, @@ -176,4 +144,9 @@ public function testBug5627(): void ]); } + public function testBug11906(): void + { + $this->analyse([__DIR__ . '/data/bug-11906.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Exceptions/data/bug-11906.php b/tests/PHPStan/Rules/Exceptions/data/bug-11906.php new file mode 100644 index 0000000000..459daf13cf --- /dev/null +++ b/tests/PHPStan/Rules/Exceptions/data/bug-11906.php @@ -0,0 +1,15 @@ +