@@ -342,9 +342,9 @@ public function processNodes(
342342 $ this ->processPendingFibers ($ expressionResultStorage );
343343 }
344344
345- private function storeResult (ExpressionResultStorage $ storage , Expr $ expr , ExpressionResult $ result ): void
345+ private function storeBeforeScope (ExpressionResultStorage $ storage , Expr $ expr , ExpressionResult $ result ): void
346346 {
347- $ storage ->storeResult ($ expr , $ result ->getBeforeScope ());
347+ $ storage ->storeBeforeScope ($ expr , $ result ->getBeforeScope ());
348348 $ this ->processPendingFibersForRequestedExpr ($ storage , $ expr , $ result ->getBeforeScope ());
349349 }
350350
@@ -2545,13 +2545,12 @@ public function processExprNode(
25452545 ExpressionContext $ context ,
25462546 ): ExpressionResult
25472547 {
2548- /*$existingExprResult = $storage->findResult ($expr);
2549- if ($existingExprResult !== null) {
2550- if ($nodeCallback instanceof ShallowNodeCallback) {
2551- return $existingExprResult ;
2548+ $ existingBeforeScope = $ storage ->findBeforeScope ($ expr );
2549+ if ($ existingBeforeScope !== null ) {
2550+ if (! $ nodeCallback instanceof ShallowNodeCallback) {
2551+ throw new ShouldNotHappenException ( sprintf ( ' Expr %s on line %d has already been analysed ' , get_class ( $ expr ), $ expr -> getStartLine ())) ;
25522552 }
2553- throw new ShouldNotHappenException(sprintf('Expr %s on line %d has already been analysed', get_class($expr), $expr->getStartLine()));
2554- }*/
2553+ }
25552554
25562555 if ($ expr instanceof Expr \CallLike && $ expr ->isFirstClassCallable ()) {
25572556 if ($ expr instanceof FuncCall) {
@@ -2567,7 +2566,7 @@ public function processExprNode(
25672566 }
25682567
25692568 $ newExprResult = $ this ->processExprNode ($ stmt , $ newExpr , $ scope , $ storage , $ nodeCallback , $ context );
2570- $ this ->storeResult ($ storage , $ expr , $ newExprResult );
2569+ $ this ->storeBeforeScope ($ storage , $ expr , $ newExprResult );
25712570 return $ newExprResult ;
25722571 }
25732572
@@ -2639,7 +2638,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
26392638 }
26402639
26412640 $ result = new ExpressionResult ($ scope , $ beforeScope , $ hasYield , $ isAlwaysTerminating , $ throwPoints , $ impurePoints );
2642- $ this ->storeResult ($ storage , $ expr , $ result );
2641+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
26432642
26442643 return $ result ;
26452644 },
@@ -2696,7 +2695,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
26962695 $ result ->getThrowPoints (),
26972696 $ result ->getImpurePoints (),
26982697 );
2699- $ this ->storeResult ($ storage , $ expr , $ result );
2698+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
27002699
27012700 return $ result ;
27022701 }
@@ -2707,7 +2706,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
27072706 );
27082707 $ scope = $ result ->getScope ();
27092708 if (!$ expr instanceof Expr \AssignOp \Coalesce) {
2710- $ this ->storeResult ($ storage , $ expr , $ result );
2709+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
27112710 }
27122711 $ hasYield = $ result ->hasYield ();
27132712 $ throwPoints = $ result ->getThrowPoints ();
@@ -3236,7 +3235,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
32363235 static fn (): MutatingScope => $ scope ->filterByTruthyValue ($ expr ),
32373236 static fn (): MutatingScope => $ scope ->filterByFalseyValue ($ expr ),
32383237 );
3239- $ this ->storeResult ($ storage , $ expr , $ result );
3238+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
32403239
32413240 return $ result ;
32423241 } elseif ($ expr instanceof StaticCall) {
@@ -3456,7 +3455,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
34563455 static fn (): MutatingScope => $ scope ->filterByTruthyValue ($ expr ),
34573456 static fn (): MutatingScope => $ scope ->filterByFalseyValue ($ expr ),
34583457 );
3459- $ this ->storeResult ($ storage , $ expr , $ result );
3458+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
34603459
34613460 return $ result ;
34623461 } elseif ($ expr instanceof StaticPropertyFetch) {
@@ -3501,7 +3500,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
35013500 [],
35023501 [],
35033502 );
3504- $ this ->storeResult ($ storage , $ expr , $ result );
3503+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
35053504
35063505 return $ result ;
35073506 } elseif ($ expr instanceof Expr \ArrowFunction) {
@@ -3514,7 +3513,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
35143513 [],
35153514 [],
35163515 );
3517- $ this ->storeResult ($ storage , $ expr , $ exprResult );
3516+ $ this ->storeBeforeScope ($ storage , $ expr , $ exprResult );
35183517 return $ exprResult ;
35193518 } elseif ($ expr instanceof ErrorSuppress) {
35203519 $ result = $ this ->processExprNode ($ stmt , $ expr ->expr , $ scope , $ storage , $ nodeCallback , $ context );
@@ -3623,7 +3622,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
36233622 static fn (): MutatingScope => $ rightResult ->getScope ()->filterByTruthyValue ($ expr ),
36243623 static fn (): MutatingScope => $ leftMergedWithRightScope ->filterByFalseyValue ($ expr ),
36253624 );
3626- $ this ->storeResult ($ storage , $ expr , $ result );
3625+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
36273626 return $ result ;
36283627 } elseif ($ expr instanceof BooleanOr || $ expr instanceof BinaryOp \LogicalOr) {
36293628 $ leftResult = $ this ->processExprNode ($ stmt , $ expr ->left , $ scope , $ storage , $ nodeCallback , $ context ->enterDeep ());
@@ -3647,7 +3646,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
36473646 static fn (): MutatingScope => $ leftMergedWithRightScope ->filterByTruthyValue ($ expr ),
36483647 static fn (): MutatingScope => $ rightResult ->getScope ()->filterByFalseyValue ($ expr ),
36493648 );
3650- $ this ->storeResult ($ storage , $ expr , $ result );
3649+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
36513650 return $ result ;
36523651 } elseif ($ expr instanceof Coalesce) {
36533652 $ nonNullabilityResult = $ this ->ensureNonNullability ($ scope , $ expr ->left );
@@ -4121,7 +4120,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
41214120 static fn (): MutatingScope => $ finalScope ->filterByTruthyValue ($ expr ),
41224121 static fn (): MutatingScope => $ finalScope ->filterByFalseyValue ($ expr ),
41234122 );
4124- $ this ->storeResult ($ storage , $ expr , $ result );
4123+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
41254124 return $ result ;
41264125
41274126 } elseif ($ expr instanceof Expr \Yield_) {
@@ -4477,7 +4476,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
44774476 static fn (): MutatingScope => $ scope ->filterByTruthyValue ($ expr ),
44784477 static fn (): MutatingScope => $ scope ->filterByFalseyValue ($ expr ),
44794478 );
4480- $ this ->storeResult ($ storage , $ expr , $ result );
4479+ $ this ->storeBeforeScope ($ storage , $ expr , $ result );
44814480 return $ result ;
44824481 }
44834482
@@ -5668,7 +5667,7 @@ private function processArgs(
56685667 $ isAlwaysTerminating = $ isAlwaysTerminating || $ closureResult ->isAlwaysTerminating ();
56695668 }
56705669
5671- $ this ->storeResult ($ storage , $ arg ->value , new ExpressionResult ($ closureResult ->getScope (), $ scopeToPass , false , $ isAlwaysTerminating , $ throwPoints , $ impurePoints ));
5670+ $ this ->storeBeforeScope ($ storage , $ arg ->value , new ExpressionResult ($ closureResult ->getScope (), $ scopeToPass , false , $ isAlwaysTerminating , $ throwPoints , $ impurePoints ));
56725671
56735672 $ uses = [];
56745673 foreach ($ arg ->value ->uses as $ use ) {
@@ -5724,7 +5723,7 @@ private function processArgs(
57245723 $ impurePoints = array_merge ($ impurePoints , $ arrowFunctionResult ->getImpurePoints ());
57255724 $ isAlwaysTerminating = $ isAlwaysTerminating || $ arrowFunctionResult ->isAlwaysTerminating ();
57265725 }
5727- $ this ->storeResult ($ storage , $ arg ->value , new ExpressionResult ($ arrowFunctionResult ->getScope (), $ scopeToPass , false , $ isAlwaysTerminating , $ throwPoints , $ impurePoints ));
5726+ $ this ->storeBeforeScope ($ storage , $ arg ->value , new ExpressionResult ($ arrowFunctionResult ->getScope (), $ scopeToPass , false , $ isAlwaysTerminating , $ throwPoints , $ impurePoints ));
57285727 } else {
57295728 $ exprType = $ scope ->getType ($ arg ->value );
57305729 $ exprResult = $ this ->processExprNode ($ stmt , $ arg ->value , $ scopeToPass , $ storage , $ nodeCallback , $ context ->enterDeep ());
0 commit comments