@@ -1315,13 +1315,18 @@ private function processStmtNode(
1315
1315
1316
1316
$ bodyScope = $ initScope ;
1317
1317
$ isIterableAtLeastOnce = TrinaryLogic::createYes ();
1318
+ $ lastCondExpr = $ stmt ->cond [count ($ stmt ->cond ) - 1 ] ?? null ;
1318
1319
foreach ($ stmt ->cond as $ condExpr ) {
1319
1320
$ condResult = $ this ->processExprNode ($ stmt , $ condExpr , $ bodyScope , static function (): void {
1320
1321
}, ExpressionContext::createDeep ());
1321
1322
$ initScope = $ condResult ->getScope ();
1322
1323
$ condResultScope = $ condResult ->getScope ();
1323
- $ condTruthiness = ($ this ->treatPhpDocTypesAsCertain ? $ condResultScope ->getType ($ condExpr ) : $ condResultScope ->getNativeType ($ condExpr ))->toBoolean ();
1324
- $ isIterableAtLeastOnce = $ isIterableAtLeastOnce ->and ($ condTruthiness ->isTrue ());
1324
+
1325
+ if ($ condExpr === $ lastCondExpr ) {
1326
+ $ condTruthiness = ($ this ->treatPhpDocTypesAsCertain ? $ condResultScope ->getType ($ condExpr ) : $ condResultScope ->getNativeType ($ condExpr ))->toBoolean ();
1327
+ $ isIterableAtLeastOnce = $ isIterableAtLeastOnce ->and ($ condTruthiness ->isTrue ());
1328
+ }
1329
+
1325
1330
$ hasYield = $ hasYield || $ condResult ->hasYield ();
1326
1331
$ throwPoints = array_merge ($ throwPoints , $ condResult ->getThrowPoints ());
1327
1332
$ impurePoints = array_merge ($ impurePoints , $ condResult ->getImpurePoints ());
@@ -1333,8 +1338,8 @@ private function processStmtNode(
1333
1338
do {
1334
1339
$ prevScope = $ bodyScope ;
1335
1340
$ bodyScope = $ bodyScope ->mergeWith ($ initScope );
1336
- foreach ($ stmt -> cond as $ condExpr ) {
1337
- $ bodyScope = $ this ->processExprNode ($ stmt , $ condExpr , $ bodyScope , static function (): void {
1341
+ if ($ lastCondExpr !== null ) {
1342
+ $ bodyScope = $ this ->processExprNode ($ stmt , $ lastCondExpr , $ bodyScope , static function (): void {
1338
1343
}, ExpressionContext::createDeep ())->getTruthyScope ();
1339
1344
}
1340
1345
$ bodyScopeResult = $ this ->processStmtNodes ($ stmt , $ stmt ->stmts , $ bodyScope , static function (): void {
@@ -1364,8 +1369,8 @@ private function processStmtNode(
1364
1369
}
1365
1370
1366
1371
$ bodyScope = $ bodyScope ->mergeWith ($ initScope );
1367
- foreach ($ stmt -> cond as $ condExpr ) {
1368
- $ bodyScope = $ this ->processExprNode ($ stmt , $ condExpr , $ bodyScope , $ nodeCallback , ExpressionContext::createDeep ())->getTruthyScope ();
1372
+ if ($ lastCondExpr !== null ) {
1373
+ $ bodyScope = $ this ->processExprNode ($ stmt , $ lastCondExpr , $ bodyScope , $ nodeCallback , ExpressionContext::createDeep ())->getTruthyScope ();
1369
1374
}
1370
1375
1371
1376
$ finalScopeResult = $ this ->processStmtNodes ($ stmt , $ stmt ->stmts , $ bodyScope , $ nodeCallback , $ context )->filterOutLoopExitPoints ();
@@ -1379,8 +1384,8 @@ private function processStmtNode(
1379
1384
$ loopScope = $ this ->processExprNode ($ stmt , $ loopExpr , $ loopScope , $ nodeCallback , ExpressionContext::createTopLevel ())->getScope ();
1380
1385
}
1381
1386
$ finalScope = $ finalScope ->generalizeWith ($ loopScope );
1382
- foreach ($ stmt -> cond as $ condExpr ) {
1383
- $ finalScope = $ finalScope ->filterByFalseyValue ($ condExpr );
1387
+ if ($ lastCondExpr !== null ) {
1388
+ $ finalScope = $ finalScope ->filterByFalseyValue ($ lastCondExpr );
1384
1389
}
1385
1390
1386
1391
foreach ($ finalScopeResult ->getExitPointsByType (Break_::class) as $ breakExitPoint ) {
0 commit comments