@@ -1104,19 +1104,23 @@ private function processStmtNode(
1104
1104
$ bodyScope = $ this ->processExprNode ($ stmt , $ stmt ->cond , $ bodyScope , $ nodeCallback , ExpressionContext::createDeep ())->getTruthyScope ();
1105
1105
$ finalScopeResult = $ this ->processStmtNodes ($ stmt , $ stmt ->stmts , $ bodyScope , $ nodeCallback , $ context )->filterOutLoopExitPoints ();
1106
1106
$ 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
+ }
1109
1115
}
1116
+
1110
1117
$ breakExitPoints = $ finalScopeResult ->getExitPointsByType (Break_::class);
1111
1118
foreach ($ breakExitPoints as $ breakExitPoint ) {
1112
1119
$ finalScope = $ finalScope ->mergeWith ($ breakExitPoint ->getScope ());
1113
1120
}
1114
1121
1115
1122
$ 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 ();
1117
1123
$ isIterableAtLeastOnce = $ beforeCondBooleanType ->isTrue ()->yes ();
1118
- $ alwaysIterates = $ condBooleanType ->isTrue ()->yes () && $ context ->isTopLevel ();
1119
- $ neverIterates = $ condBooleanType ->isFalse ()->yes () && $ context ->isTopLevel ();
1120
1124
$ nodeCallback (new BreaklessWhileLoopNode ($ stmt , $ finalScopeResult ->getExitPoints ()), $ bodyScopeMaybeRan );
1121
1125
1122
1126
if ($ alwaysIterates ) {
0 commit comments