@@ -172,7 +172,7 @@ static function (GeneratorScope $scope) use ($stmt, $expr, $context, $alternativ
172172 yield from $ processVarGen ;
173173 $ scope = $ processVarGen ->getReturn ();
174174 if (!$ varChangedScope ) {
175- $ stmtVarGen = $ this ->processStmtVarAnnotation ($ scope , $ stmt , null );
175+ $ stmtVarGen = $ this ->processStmtVarAnnotation ($ scope , $ stmt , null , $ alternativeNodeCallback );
176176 yield from $ stmtVarGen ;
177177 $ scope = $ stmtVarGen ->getReturn ();
178178 }
@@ -277,9 +277,10 @@ private function processVarAnnotation(GeneratorScope $scope, array $variableName
277277 }
278278
279279 /**
280+ * @param (callable(Node, Scope, callable(Node, Scope): void): void)|null $alternativeNodeCallback
280281 * @return Generator<int, ExprAnalysisRequest|NodeCallbackRequest|TypeExprRequest, ExprAnalysisResult|TypeExprResult, GeneratorScope>
281282 */
282- private function processStmtVarAnnotation (GeneratorScope $ scope , Node \Stmt $ stmt , ?Expr $ defaultExpr ): Generator
283+ private function processStmtVarAnnotation (GeneratorScope $ scope , Node \Stmt $ stmt , ?Expr $ defaultExpr, ? callable $ alternativeNodeCallback ): Generator
283284 {
284285 $ function = $ scope ->getFunction ();
285286 $ variableLessTags = [];
@@ -333,7 +334,7 @@ private function processStmtVarAnnotation(GeneratorScope $scope, Node\Stmt $stmt
333334 $ variableNode = new Variable ($ name , $ stmt ->getAttributes ());
334335 $ originalType = $ scope ->getVariableType ($ name );
335336 if (!$ originalType ->equals ($ varTag ->getType ())) {
336- yield new NodeCallbackRequest (new VarTagChangedExpressionTypeNode ($ varTag , $ variableNode ), $ scope );
337+ yield new NodeCallbackRequest (new VarTagChangedExpressionTypeNode ($ varTag , $ variableNode ), $ scope, $ alternativeNodeCallback );
337338 }
338339
339340 $ variableNodeResult = yield new ExprAnalysisRequest ($ stmt , $ variableNode , $ scope , ExpressionContext::createDeep (), new NoopNodeCallback ());
@@ -379,7 +380,7 @@ private function processAssignVar(
379380 bool $ enterExpressionAssign ,
380381 ): Generator
381382 {
382- yield new NodeCallbackRequest ($ var , $ enterExpressionAssign ? $ scope ->enterExpressionAssign ($ var ) : $ scope );
383+ yield new NodeCallbackRequest ($ var , $ enterExpressionAssign ? $ scope ->enterExpressionAssign ($ var ) : $ scope, $ alternativeNodeCallback );
383384
384385 $ isAssignOp = $ assignedExpr instanceof Expr \AssignOp && !$ enterExpressionAssign ;
385386 if ($ var instanceof Variable && is_string ($ var ->name )) {
@@ -451,7 +452,7 @@ private function processAssignVar(
451452 yield from $ sureTypesGen ;
452453 $ conditionalExpressions = $ sureTypesGen ->getReturn ();
453454
454- yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedExpr ), $ scopeBeforeAssignEval );
455+ yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedExpr ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
455456
456457 $ assignVarGen = $ scope ->assignVariable ($ var ->name , $ type , $ result ->nativeType , TrinaryLogic::createYes ());
457458 yield from $ assignVarGen ;
@@ -526,7 +527,7 @@ private function processAssignVar(
526527
527528 // Callback was already called for last dim at the beginning of the method.
528529 if ($ key !== $ lastDimKey ) {
529- yield new NodeCallbackRequest ($ dimFetch , $ enterExpressionAssign ? $ scope ->enterExpressionAssign ($ dimFetch ) : $ scope );
530+ yield new NodeCallbackRequest ($ dimFetch , $ enterExpressionAssign ? $ scope ->enterExpressionAssign ($ dimFetch ) : $ scope, $ alternativeNodeCallback );
530531 }
531532
532533 if ($ dimExpr === null ) {
@@ -620,13 +621,13 @@ private function processAssignVar(
620621
621622 if ($ varType ->isArray ()->yes () || !(new ObjectType (ArrayAccess::class))->isSuperTypeOf ($ varType )->yes ()) {
622623 if ($ var instanceof Variable && is_string ($ var ->name )) {
623- yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedPropertyExpr ), $ scopeBeforeAssignEval );
624+ yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedPropertyExpr ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
624625 $ assignVarGen = $ scope ->assignVariable ($ var ->name , $ valueToWrite , $ nativeValueToWrite , TrinaryLogic::createYes ());
625626 yield from $ assignVarGen ;
626627 $ scope = $ assignVarGen ->getReturn ();
627628 } else {
628629 if ($ var instanceof PropertyFetch || $ var instanceof StaticPropertyFetch) {
629- yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scopeBeforeAssignEval );
630+ yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
630631 if ($ var instanceof PropertyFetch && $ var ->name instanceof Node \Identifier && !$ isAssignOp ) {
631632 $ scope = $ scope ->assignInitializedProperty ((yield new TypeExprRequest ($ var ->var ))->type , $ var ->name ->toString ());
632633 }
@@ -641,9 +642,9 @@ private function processAssignVar(
641642 }
642643 } else {
643644 if ($ var instanceof Variable) {
644- yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedPropertyExpr ), $ scopeBeforeAssignEval );
645+ yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedPropertyExpr ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
645646 } elseif ($ var instanceof PropertyFetch || $ var instanceof StaticPropertyFetch) {
646- yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scopeBeforeAssignEval );
647+ yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
647648 if ($ var instanceof PropertyFetch && $ var ->name instanceof Node \Identifier && !$ isAssignOp ) {
648649 $ scope = $ scope ->assignInitializedProperty ((yield new TypeExprRequest ($ var ->var ))->type , $ var ->name ->toString ());
649650 }
@@ -721,7 +722,7 @@ private function processAssignVar(
721722 if ($ propertyName !== null && $ propertyHolderType ->hasInstanceProperty ($ propertyName )->yes ()) {
722723 $ propertyReflection = $ propertyHolderType ->getInstanceProperty ($ propertyName , $ scope );
723724 $ assignedExprType = $ result ->type ;
724- yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval );
725+ yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
725726 if ($ propertyReflection ->canChangeTypeAfterAssignment ()) {
726727 if ($ propertyReflection ->hasNativeType ()) {
727728 $ propertyNativeType = $ propertyReflection ->getNativeType ();
@@ -773,7 +774,7 @@ private function processAssignVar(
773774 } else {
774775 // fallback
775776 $ assignedExprType = $ result ->type ;
776- yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval );
777+ yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
777778 $ assignExprGen = $ scope ->assignExpression ($ var , $ assignedExprType , $ result ->nativeType );
778779 yield from $ assignExprGen ;
779780 $ scope = $ assignExprGen ->getReturn ();
@@ -838,7 +839,7 @@ private function processAssignVar(
838839 if ($ propertyName !== null ) {
839840 $ propertyReflection = $ scope ->getStaticPropertyReflection ($ propertyHolderType , $ propertyName );
840841 $ assignedExprType = $ result ->type ;
841- yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval );
842+ yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
842843 if ($ propertyReflection !== null && $ propertyReflection ->canChangeTypeAfterAssignment ()) {
843844 if ($ propertyReflection ->hasNativeType ()) {
844845 $ propertyNativeType = $ propertyReflection ->getNativeType ();
@@ -875,7 +876,7 @@ private function processAssignVar(
875876 } else {
876877 // fallback
877878 $ assignedExprType = $ result ->type ;
878- yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval );
879+ yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedExpr , $ isAssignOp ), $ scopeBeforeAssignEval, $ alternativeNodeCallback );
879880 $ assignExprGen = $ scope ->assignExpression ($ var , $ assignedExprType , $ result ->nativeType );
880881 yield from $ assignExprGen ;
881882 $ scope = $ assignExprGen ->getReturn ();
@@ -911,7 +912,7 @@ private function processAssignVar(
911912 $ itemScope = $ itemScope ->enterExpressionAssign ($ arrayItem ->value );
912913 }
913914 $ itemScope = $ this ->lookForSetAllowedUndefinedExpressions ($ itemScope , $ arrayItem ->value );
914- yield new NodeCallbackRequest ($ arrayItem , $ itemScope );
915+ yield new NodeCallbackRequest ($ arrayItem , $ itemScope, $ alternativeNodeCallback );
915916 if ($ arrayItem ->key !== null ) {
916917 $ keyResult = yield new ExprAnalysisRequest ($ stmt , $ arrayItem ->key , $ itemScope , $ context ->enterDeep (), $ alternativeNodeCallback );
917918 $ hasYield = $ hasYield || $ keyResult ->hasYield ;
@@ -1051,13 +1052,13 @@ static function (GeneratorScope $scope): Generator {
10511052 }
10521053
10531054 if ($ var instanceof Variable && is_string ($ var ->name )) {
1054- yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedPropertyExpr ), $ scope );
1055+ yield new NodeCallbackRequest (new VariableAssignNode ($ var , $ assignedPropertyExpr ), $ scope, $ alternativeNodeCallback );
10551056 $ assignVarGen = $ scope ->assignVariable ($ var ->name , $ valueToWrite , $ nativeValueToWrite , TrinaryLogic::createYes ());
10561057 yield from $ assignVarGen ;
10571058 $ scope = $ assignVarGen ->getReturn ();
10581059 } else {
10591060 if ($ var instanceof PropertyFetch || $ var instanceof StaticPropertyFetch) {
1060- yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scope );
1061+ yield new NodeCallbackRequest (new PropertyAssignNode ($ var , $ assignedPropertyExpr , $ isAssignOp ), $ scope, $ alternativeNodeCallback );
10611062 }
10621063 $ assignExprGen = $ scope ->assignExpression (
10631064 $ var ,
0 commit comments