@@ -2880,6 +2880,7 @@ private function enterAnonymousFunctionWithoutReflection(
28802880 $ nativeTypes [$ paramExprString ] = $ parameterType ;
28812881 }
28822882
2883+ $ nonRefVariableNames = [];
28832884 foreach ($ closure ->uses as $ use ) {
28842885 if (!is_string ($ use ->var ->name )) {
28852886 throw new ShouldNotHappenException ();
@@ -2891,34 +2892,41 @@ private function enterAnonymousFunctionWithoutReflection(
28912892 $ nativeTypes [$ paramExprString ] = new MixedType ();
28922893 continue ;
28932894 }
2895+ $ nonRefVariableNames [$ variableName ] = true ;
28942896 if ($ this ->hasVariableType ($ variableName )->no ()) {
28952897 $ variableType = new ErrorType ();
28962898 } else {
28972899 $ variableType = $ this ->getVariableType ($ variableName );
28982900 $ nativeTypes [$ paramExprString ] = $ this ->getNativeType ($ use ->var );
28992901 }
29002902 $ expressionTypes [$ paramExprString ] = ExpressionTypeHolder::createYes ($ variableType );
2903+ }
29012904
2902- foreach ($ this ->expressionTypes as $ exprString => $ typeHolder ) {
2903- $ expr = $ this ->exprStringToExpr ((string ) $ exprString );
2904- if ($ expr === null ) {
2905- continue ;
2906- }
2907- if ($ expr instanceof Variable) {
2908- continue ;
2909- }
2910- $ variable = (new NodeFinder ())->findFirst ([$ expr ], static fn (Node $ node ): bool => $ node instanceof Variable);
2905+ foreach ($ this ->expressionTypes as $ exprString => $ typeHolder ) {
2906+ $ expr = $ this ->exprStringToExpr ((string ) $ exprString );
2907+ if ($ expr === null ) {
2908+ continue ;
2909+ }
2910+ if ($ expr instanceof Variable) {
2911+ continue ;
2912+ }
2913+ $ variables = (new NodeFinder ())->findInstanceOf ([$ expr ], Variable::class);
2914+ if ($ variables === []) {
2915+ continue ;
2916+ }
2917+ foreach ($ variables as $ variable ) {
29112918 if (!$ variable instanceof Variable) {
2912- continue ;
2919+ continue 2 ;
29132920 }
29142921 if (!is_string ($ variable ->name )) {
2915- continue ;
2922+ continue 2 ;
29162923 }
2917- if ($ variable ->name !== $ variableName ) {
2918- continue ;
2924+ if (! array_key_exists ( $ variable ->name , $ nonRefVariableNames ) ) {
2925+ continue 2 ;
29192926 }
2920- $ expressionTypes [$ exprString ] = $ typeHolder ;
29212927 }
2928+
2929+ $ expressionTypes [$ exprString ] = $ typeHolder ;
29222930 }
29232931
29242932 if ($ this ->hasVariableType ('this ' )->yes () && !$ closure ->static ) {
0 commit comments