@@ -1375,12 +1375,12 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1375
1375
$ closureScope = $ this ->enterAnonymousFunctionWithoutReflection ($ node , $ callableParameters );
1376
1376
$ closureReturnStatements = [];
1377
1377
$ closureYieldStatements = [];
1378
- $ closureExecutionEnds = [] ;
1378
+ $ onlyNeverExecutionEnds = null ;
1379
1379
$ closureImpurePoints = [];
1380
1380
$ invalidateExpressions = [];
1381
1381
1382
1382
try {
1383
- $ closureStatementResult = $ this ->nodeScopeResolver ->processStmtNodes ($ node , $ node ->stmts , $ closureScope , static function (Node $ node , Scope $ scope ) use ($ closureScope , &$ closureReturnStatements , &$ closureYieldStatements , &$ closureExecutionEnds , &$ closureImpurePoints , &$ invalidateExpressions ): void {
1383
+ $ closureStatementResult = $ this ->nodeScopeResolver ->processStmtNodes ($ node , $ node ->stmts , $ closureScope , static function (Node $ node , Scope $ scope ) use ($ closureScope , &$ closureReturnStatements , &$ closureYieldStatements , &$ onlyNeverExecutionEnds , &$ closureImpurePoints , &$ invalidateExpressions ): void {
1384
1384
if ($ scope ->getAnonymousFunctionReflection () !== $ closureScope ->getAnonymousFunctionReflection ()) {
1385
1385
return ;
1386
1386
}
@@ -1405,16 +1405,24 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1405
1405
if ($ node ->getStatementResult ()->isAlwaysTerminating ()) {
1406
1406
foreach ($ node ->getStatementResult ()->getExitPoints () as $ exitPoint ) {
1407
1407
if ($ exitPoint ->getStatement () instanceof Node \Stmt \Return_) {
1408
+ $ onlyNeverExecutionEnds = false ;
1408
1409
continue ;
1409
1410
}
1410
1411
1411
- $ closureExecutionEnds [] = $ node ;
1412
+ if ($ onlyNeverExecutionEnds === null ) {
1413
+ $ onlyNeverExecutionEnds = true ;
1414
+ }
1415
+
1412
1416
break ;
1413
1417
}
1414
1418
1415
1419
if (count ($ node ->getStatementResult ()->getExitPoints ()) === 0 ) {
1416
- $ closureExecutionEnds [] = $ node ;
1420
+ if ($ onlyNeverExecutionEnds === null ) {
1421
+ $ onlyNeverExecutionEnds = true ;
1422
+ }
1417
1423
}
1424
+ } else {
1425
+ $ onlyNeverExecutionEnds = false ;
1418
1426
}
1419
1427
1420
1428
return ;
@@ -1449,13 +1457,13 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
1449
1457
}
1450
1458
1451
1459
if (count ($ returnTypes ) === 0 ) {
1452
- if (count ( $ closureExecutionEnds ) > 0 && !$ hasNull ) {
1460
+ if ($ onlyNeverExecutionEnds === true && !$ hasNull ) {
1453
1461
$ returnType = new NonAcceptingNeverType ();
1454
1462
} else {
1455
1463
$ returnType = new VoidType ();
1456
1464
}
1457
1465
} else {
1458
- if (count ( $ closureExecutionEnds ) > 0 ) {
1466
+ if ($ onlyNeverExecutionEnds === true ) {
1459
1467
$ returnTypes [] = new NonAcceptingNeverType ();
1460
1468
}
1461
1469
if ($ hasNull ) {
0 commit comments