Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -176,4 +144,9 @@ public function testBug5627(): void
]);
}

public function testBug11906(): void
{
$this->analyse([__DIR__ . '/data/bug-11906.php'], []);
}

}
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Exceptions/data/bug-11906.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace Bug11906;

function func(): void {
try {
throw new LogicException('test');
} catch (LogicException $e) {
// This catch-block should cause line 9 to not be treated as an exit point
} finally {
if (getenv('FOO')) {
return;
}
}
}
Loading