diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php index b1470cf51ee..54e63533988 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php @@ -112,6 +112,7 @@ public static function analyze( && !$method_storage->assertions && !$method_storage->if_true_assertions && !$method_storage->if_false_assertions + && !$method_storage->throws ) { if (IssueBuffer::accepts( new \Psalm\Issue\UnusedMethodCall( diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 2c3c0939d49..3b928ce66e7 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -1162,6 +1162,27 @@ private function assert(?string $val): void { $a = new A(); echo $a->getVal(null);', ], + 'NotUnusedWhenThrows' => [ + 'validate(); + ', + ], '__halt_compiler_no_usage_check' => [ '