diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3da79de067..125c8e5d3f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -433,11 +433,6 @@ parameters: count: 6 path: src/Reflection/InitializerExprTypeResolver.php - - - message: "#^Dead catch \\- PHPStan\\\\BetterReflection\\\\Identifier\\\\Exception\\\\InvalidIdentifierName is never thrown in the try block\\.$#" - count: 1 - path: src/Reflection/SignatureMap/NativeFunctionReflectionProvider.php - - message: "#^Creating new PHPStan\\\\Php8StubsMap is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#" count: 1 @@ -1772,11 +1767,6 @@ parameters: count: 1 path: tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php - - - message: "#^Dead catch \\- OutOfBoundsException is never thrown in the try block\\.$#" - count: 1 - path: tests/PHPStan/Reflection/SignatureMap/SignatureMapParserTest.php - - message: """ #^Instantiation of deprecated class PHPStan\\\\Rules\\\\Arrays\\\\AppendedArrayItemTypeRule\\: diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 940f44c282..ba760baaf0 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -1294,17 +1294,16 @@ private function processStmtNode( // explicit only if (count($matchingThrowPoints) === 0) { foreach ($throwPoints as $throwPointIndex => $throwPoint) { - if (!$throwPoint->isExplicit()) { - continue; - } - foreach ($catchTypes as $catchTypeIndex => $catchTypeItem) { if ($catchTypeItem->isSuperTypeOf($throwPoint->getType())->no()) { continue; } - $matchingThrowPoints[$throwPointIndex] = $throwPoint; $matchingCatchTypes[$catchTypeIndex] = true; + if (!$throwPoint->isExplicit()) { + continue; + } + $matchingThrowPoints[$throwPointIndex] = $throwPoint; } } } @@ -1322,7 +1321,6 @@ private function processStmtNode( } $matchingThrowPoints[$throwPointIndex] = $throwPoint; - $matchingCatchTypes[$catchTypeIndex] = true; } } } diff --git a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php index ec90c53b56..2f9d5a7d8b 100644 --- a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php @@ -475,4 +475,9 @@ public function testMagicMethods(): void ]); } + public function testBug9406(): void + { + $this->analyse([__DIR__ . '/data/bug-9406.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Exceptions/data/bug-9406.php b/tests/PHPStan/Rules/Exceptions/data/bug-9406.php new file mode 100644 index 0000000000..0bf40f3c92 --- /dev/null +++ b/tests/PHPStan/Rules/Exceptions/data/bug-9406.php @@ -0,0 +1,37 @@ +