From 9c9e57cf6ba91352e9f45bf890e833477b373d58 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 6 Jan 2019 12:39:18 -0500 Subject: [PATCH] Fix #1153 - ignore redundant conditions in finally block --- .../Analyzer/Statements/Block/TryAnalyzer.php | 18 ++++++++++++++++++ tests/TryCatchTest.php | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) 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' => [ + '