@@ -1104,19 +1104,23 @@ private function processStmtNode(
11041104 $ bodyScope = $ this ->processExprNode ($ stmt , $ stmt ->cond , $ bodyScope , $ nodeCallback , ExpressionContext::createDeep ())->getTruthyScope ();
11051105 $ finalScopeResult = $ this ->processStmtNodes ($ stmt , $ stmt ->stmts , $ bodyScope , $ nodeCallback , $ context )->filterOutLoopExitPoints ();
11061106 $ finalScope = $ finalScopeResult ->getScope ()->filterByFalseyValue ($ stmt ->cond );
1107- foreach ($ finalScopeResult ->getExitPointsByType (Continue_::class) as $ continueExitPoint ) {
1108- $ finalScope = $ finalScope ->mergeWith ($ continueExitPoint ->getScope ());
1107+
1108+ $ condBooleanType = ($ this ->treatPhpDocTypesAsCertain ? $ bodyScopeMaybeRan ->getType ($ stmt ->cond ) : $ bodyScopeMaybeRan ->getNativeType ($ stmt ->cond ))->toBoolean ();
1109+ $ alwaysIterates = $ condBooleanType ->isTrue ()->yes () && $ context ->isTopLevel ();
1110+ $ neverIterates = $ condBooleanType ->isFalse ()->yes () && $ context ->isTopLevel ();
1111+ if (!$ alwaysIterates ) {
1112+ foreach ($ finalScopeResult ->getExitPointsByType (Continue_::class) as $ continueExitPoint ) {
1113+ $ finalScope = $ finalScope ->mergeWith ($ continueExitPoint ->getScope ());
1114+ }
11091115 }
1116+
11101117 $ breakExitPoints = $ finalScopeResult ->getExitPointsByType (Break_::class);
11111118 foreach ($ breakExitPoints as $ breakExitPoint ) {
11121119 $ finalScope = $ finalScope ->mergeWith ($ breakExitPoint ->getScope ());
11131120 }
11141121
11151122 $ beforeCondBooleanType = ($ this ->treatPhpDocTypesAsCertain ? $ scope ->getType ($ stmt ->cond ) : $ scope ->getNativeType ($ stmt ->cond ))->toBoolean ();
1116- $ condBooleanType = ($ this ->treatPhpDocTypesAsCertain ? $ bodyScopeMaybeRan ->getType ($ stmt ->cond ) : $ bodyScopeMaybeRan ->getNativeType ($ stmt ->cond ))->toBoolean ();
11171123 $ isIterableAtLeastOnce = $ beforeCondBooleanType ->isTrue ()->yes ();
1118- $ alwaysIterates = $ condBooleanType ->isTrue ()->yes () && $ context ->isTopLevel ();
1119- $ neverIterates = $ condBooleanType ->isFalse ()->yes () && $ context ->isTopLevel ();
11201124 $ nodeCallback (new BreaklessWhileLoopNode ($ stmt , $ finalScopeResult ->getExitPoints ()), $ bodyScopeMaybeRan );
11211125
11221126 if ($ alwaysIterates ) {
0 commit comments