@@ -3708,41 +3708,21 @@ private function enterAnonymousFunctionWithoutReflection(
37083708 foreach ($ this ->invalidateStaticExpressions ($ this ->expressionTypes ) as $ exprString => $ typeHolder ) {
37093709 $ expr = $ typeHolder ->getExpr ();
37103710
3711- if (
3712- $ expr instanceof PropertyFetch
3713- && $ expr ->name instanceof Node \Identifier
3714- && $ expr ->var instanceof Variable
3715- && is_string ($ expr ->var ->name )
3716- && $ expr ->var ->name === 'this '
3717- && !$ closure ->static
3718- && $ this ->hasVariableType ('this ' )->yes ()
3719- && $ this ->phpVersion ->supportsReadOnlyProperties ()
3720- ) {
3721- $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3722- if ($ propertyReflection === null ) {
3723- continue ;
3724- }
3725- $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3726- if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3727- continue ;
3728- }
3729- } else {
3730- if ($ expr instanceof Variable) {
3731- continue ;
3732- }
3711+ if ($ expr instanceof Variable) {
3712+ continue ;
3713+ }
37333714
3734- $ variables = (new NodeFinder ())->findInstanceOf ([$ expr ], Variable::class);
3735- if ($ variables === [] && !$ this ->expressionTypeIsUnchangeable ($ typeHolder )) {
3736- continue ;
3737- }
3715+ $ variables = (new NodeFinder ())->findInstanceOf ([$ expr ], Variable::class);
3716+ if ($ variables === [] && !$ this ->expressionTypeIsUnchangeable ($ typeHolder )) {
3717+ continue ;
3718+ }
37383719
3739- foreach ($ variables as $ variable ) {
3740- if (!is_string ($ variable ->name )) {
3741- continue 2 ;
3742- }
3743- if (!array_key_exists ($ variable ->name , $ nonRefVariableNames )) {
3744- continue 2 ;
3745- }
3720+ foreach ($ variables as $ variable ) {
3721+ if (!is_string ($ variable ->name )) {
3722+ continue 2 ;
3723+ }
3724+ if (!array_key_exists ($ variable ->name , $ nonRefVariableNames )) {
3725+ continue 2 ;
37463726 }
37473727 }
37483728
@@ -3753,6 +3733,34 @@ private function enterAnonymousFunctionWithoutReflection(
37533733 $ node = new Variable ('this ' );
37543734 $ expressionTypes ['$this ' ] = ExpressionTypeHolder::createYes ($ node , $ this ->getType ($ node ));
37553735 $ nativeTypes ['$this ' ] = ExpressionTypeHolder::createYes ($ node , $ this ->getNativeType ($ node ));
3736+
3737+ if ($ this ->phpVersion ->supportsReadOnlyProperties ()) {
3738+ foreach ($ this ->invalidateStaticExpressions ($ this ->expressionTypes ) as $ exprString => $ typeHolder ) {
3739+ $ expr = $ typeHolder ->getExpr ();
3740+
3741+ if (
3742+ !$ expr instanceof PropertyFetch
3743+ || !$ expr ->name instanceof Node \Identifier
3744+ || !$ expr ->var instanceof Variable
3745+ || !is_string ($ expr ->var ->name )
3746+ || $ expr ->var ->name !== 'this '
3747+ ) {
3748+ continue ;
3749+ }
3750+
3751+ $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3752+ if ($ propertyReflection === null ) {
3753+ continue ;
3754+ }
3755+
3756+ $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3757+ if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3758+ continue ;
3759+ }
3760+
3761+ $ expressionTypes [$ exprString ] = $ typeHolder ;
3762+ }
3763+ }
37563764 }
37573765
37583766 return $ this ->scopeFactory ->create (
0 commit comments