diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php index 3b46962db..f3c89fd58 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/TryAnalyzer.php @@ -357,7 +357,25 @@ class TryAnalyzer } if ($stmt->finally) { + $suppressed_issues = $statements_analyzer->getSuppressedIssues(); + + if (!in_array('RedundantCondition', $suppressed_issues, true)) { + $statements_analyzer->addSuppressedIssues(['RedundantCondition']); + } + + if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) { + $statements_analyzer->addSuppressedIssues(['RedundantConditionGivenDocblockType']); + } + $statements_analyzer->analyze($stmt->finally->stmts, $context); + + if (!in_array('RedundantCondition', $suppressed_issues, true)) { + $statements_analyzer->removeSuppressedIssues(['RedundantCondition']); + } + + if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) { + $statements_analyzer->removeSuppressedIssues(['RedundantConditionGivenDocblockType']); + } } if ($context->collect_references) { diff --git a/tests/TryCatchTest.php b/tests/TryCatchTest.php index e46995069..4f5218ed6 100644 --- a/tests/TryCatchTest.php +++ b/tests/TryCatchTest.php @@ -144,6 +144,25 @@ class TryCatchTest extends TestCase echo $a;', ], + 'noRedundantConditionsInFinally' => [ + '