diff --git a/src/Analyser/ExprHandler/FuncCallHandler.php b/src/Analyser/ExprHandler/FuncCallHandler.php index 5df15e3fd9..2e308bb43e 100644 --- a/src/Analyser/ExprHandler/FuncCallHandler.php +++ b/src/Analyser/ExprHandler/FuncCallHandler.php @@ -596,8 +596,8 @@ private function getFunctionThrowPoint( } $throwType = $functionReflection->getThrowType(); - if ($throwType === null && $parametersAcceptor !== null) { - $returnType = $parametersAcceptor->getReturnType(); + if ($throwType === null) { + $returnType = $scope->getType($normalizedFuncCall); if ($returnType instanceof NeverType && $returnType->isExplicit()) { $throwType = new ObjectType(Throwable::class); } diff --git a/src/Analyser/ExprHandler/Helper/MethodThrowPointHelper.php b/src/Analyser/ExprHandler/Helper/MethodThrowPointHelper.php index 05b1314b5b..5401642d4c 100644 --- a/src/Analyser/ExprHandler/Helper/MethodThrowPointHelper.php +++ b/src/Analyser/ExprHandler/Helper/MethodThrowPointHelper.php @@ -75,7 +75,7 @@ public function getThrowPoint( $throwType = $methodReflection->getThrowType(); if ($throwType === null) { - $returnType = $parametersAcceptor->getReturnType(); + $returnType = $scope->getType($normalizedMethodCall); if ($returnType instanceof NeverType && $returnType->isExplicit()) { $throwType = new ObjectType(Throwable::class); } diff --git a/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php b/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php index 577374aee2..7c7bda7514 100644 --- a/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php +++ b/tests/PHPStan/Rules/Exceptions/AbilityToDisableImplicitThrowsTest.php @@ -87,6 +87,16 @@ public function testBug13806(): void ]); } + public function testBug7799(): void + { + $this->analyse([__DIR__ . '/data/bug-7799.php'], [ + [ + 'Dead catch - Exception is never thrown in the try block.', + 19, + ], + ]); + } + public static function getAdditionalConfigFiles(): array { return array_merge( diff --git a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php index e7e10cb9e9..76ddadd647 100644 --- a/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php +++ b/tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php @@ -816,4 +816,9 @@ public function testBug6574(): void ]); } + public function testBug7799(): void + { + $this->analyse([__DIR__ . '/data/bug-7799.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Exceptions/data/bug-7799.php b/tests/PHPStan/Rules/Exceptions/data/bug-7799.php new file mode 100644 index 0000000000..d20881f130 --- /dev/null +++ b/tests/PHPStan/Rules/Exceptions/data/bug-7799.php @@ -0,0 +1,21 @@ +