File tree Expand file tree Collapse file tree 2 files changed +32
-12
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 2 files changed +32
-12
lines changed Original file line number Diff line number Diff line change @@ -3764,22 +3764,34 @@ private function enterAnonymousFunctionWithoutReflection(
37643764
37653765 if (
37663766 !$ expr instanceof PropertyFetch
3767- || !$ expr ->name instanceof Node \Identifier
3768- || !$ expr ->var instanceof Variable
3769- || !is_string ($ expr ->var ->name )
3770- || $ expr ->var ->name !== 'this '
37713767 ) {
37723768 continue ;
37733769 }
37743770
3775- $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3776- if ($ propertyReflection === null ) {
3777- continue ;
3778- }
3771+ while ($ expr instanceof PropertyFetch) {
3772+ if ($ expr ->var instanceof Variable) {
3773+ if (
3774+ ! $ expr ->name instanceof Node \Identifier
3775+ || !is_string ($ expr ->var ->name )
3776+ || $ expr ->var ->name !== 'this '
3777+ ) {
3778+ continue 2 ;
3779+ }
3780+ } elseif (!$ expr ->var instanceof PropertyFetch) {
3781+ continue 2 ;
3782+ }
37793783
3780- $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3781- if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3782- continue ;
3784+ $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3785+ if ($ propertyReflection === null ) {
3786+ continue 2 ;
3787+ }
3788+
3789+ $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3790+ if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3791+ continue 2 ;
3792+ }
3793+
3794+ $ expr = $ expr ->var ;
37833795 }
37843796
37853797 $ expressionTypes [$ exprString ] = $ typeHolder ;
Original file line number Diff line number Diff line change 66
77class Foo
88{
9- public function __construct (public string $ value )
9+ public function __construct (
10+ public string $ value ,
11+ readonly public string $ readonlyValue ,
12+ )
1013 {
1114 }
1215}
@@ -27,13 +30,18 @@ public function bar(): void
2730 if ($ this ->foo ->value === '' ) {
2831 return ;
2932 }
33+ if ($ this ->foo ->readonlyValue === '' ) {
34+ return ;
35+ }
3036
3137 assertType (Foo::class, $ this ->foo );
3238 assertType ('non-empty-string ' , $ this ->foo ->value );
39+ assertType ('non-empty-string ' , $ this ->foo ->readonlyValue );
3340
3441 $ test = function () {
3542 assertType (Foo::class, $ this ->foo );
3643 assertType ('string ' , $ this ->foo ->value );
44+ assertType ('non-empty-string ' , $ this ->foo ->readonlyValue );
3745 };
3846
3947 $ test ();
You can’t perform that action at this time.
0 commit comments