From 34c133d5d08da1379030f7f8e7322d1f1f574a3e Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 13 Dec 2017 22:04:37 -0500 Subject: [PATCH] Add for post conditions to assignment map analysis --- src/Psalm/Checker/Statements/Block/LoopChecker.php | 2 +- tests/RedundantConditionTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Checker/Statements/Block/LoopChecker.php b/src/Psalm/Checker/Statements/Block/LoopChecker.php index 50e2645eb..0e9300de3 100644 --- a/src/Psalm/Checker/Statements/Block/LoopChecker.php +++ b/src/Psalm/Checker/Statements/Block/LoopChecker.php @@ -40,7 +40,7 @@ class LoopChecker $assignment_mapper = new \Psalm\Visitor\AssignmentMapVisitor($loop_scope->loop_context->self); $traverser->addVisitor($assignment_mapper); - $traverser->traverse($stmts); + $traverser->traverse(array_merge($stmts, $post_conditions)); $assignment_map = $assignment_mapper->getAssignmentMap(); diff --git a/tests/RedundantConditionTest.php b/tests/RedundantConditionTest.php index d7cea16d5..400a1d9fd 100644 --- a/tests/RedundantConditionTest.php +++ b/tests/RedundantConditionTest.php @@ -188,6 +188,19 @@ class RedundantConditionTest extends TestCase $ch = curl_init(); if (!$ch) {}', ], + 'noRedundantConditionInForCheck' => [ + 'next) {} + } + }', + ], ]; }