@@ -4639,6 +4639,9 @@ private function processClosureNode(
46394639 throw new ShouldNotHappenException ();
46404640 }
46414641
4642+ $ returnType = $ closureType ->getReturnType ();
4643+ $ isAlwaysTerminating = ($ returnType instanceof NeverType && $ returnType ->isExplicit ());
4644+
46424645 $ nodeCallback (new InClosureNode ($ closureType , $ expr ), $ closureScope );
46434646
46444647 $ executionEnds = [];
@@ -4690,7 +4693,7 @@ private function processClosureNode(
46904693 array_merge ($ statementResult ->getImpurePoints (), $ closureImpurePoints ),
46914694 ), $ closureScope );
46924695
4693- return new ProcessClosureResult ($ scope , $ statementResult ->getThrowPoints (), $ statementResult ->getImpurePoints (), $ invalidateExpressions );
4696+ return new ProcessClosureResult ($ scope , $ statementResult ->getThrowPoints (), $ statementResult ->getImpurePoints (), $ invalidateExpressions, $ isAlwaysTerminating );
46944697 }
46954698
46964699 $ count = 0 ;
@@ -4736,7 +4739,7 @@ private function processClosureNode(
47364739 array_merge ($ statementResult ->getImpurePoints (), $ closureImpurePoints ),
47374740 ), $ closureScope );
47384741
4739- return new ProcessClosureResult ($ scope ->processClosureScope ($ closureResultScope , null , $ byRefUses ), $ statementResult ->getThrowPoints (), $ statementResult ->getImpurePoints (), $ invalidateExpressions );
4742+ return new ProcessClosureResult ($ scope ->processClosureScope ($ closureResultScope , null , $ byRefUses ), $ statementResult ->getThrowPoints (), $ statementResult ->getImpurePoints (), $ invalidateExpressions, $ isAlwaysTerminating );
47404743 }
47414744
47424745 /**
@@ -5180,6 +5183,7 @@ private function processArgs(
51805183 if ($ callCallbackImmediately ) {
51815184 $ throwPoints = array_merge ($ throwPoints , array_map (static fn (ThrowPoint $ throwPoint ) => $ throwPoint ->isExplicit () ? ThrowPoint::createExplicit ($ scope , $ throwPoint ->getType (), $ arg ->value , $ throwPoint ->canContainAnyThrowable ()) : ThrowPoint::createImplicit ($ scope , $ arg ->value ), $ closureResult ->getThrowPoints ()));
51825185 $ impurePoints = array_merge ($ impurePoints , $ closureResult ->getImpurePoints ());
5186+ $ isAlwaysTerminating = $ isAlwaysTerminating || $ closureResult ->isAlwaysTerminating ();
51835187 }
51845188
51855189 $ uses = [];
0 commit comments