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 @@ -3741,22 +3741,34 @@ private function enterAnonymousFunctionWithoutReflection(
37413741
37423742 if (
37433743 !$ expr instanceof PropertyFetch
3744- || !$ expr ->name instanceof Node \Identifier
3745- || !$ expr ->var instanceof Variable
3746- || !is_string ($ expr ->var ->name )
3747- || $ expr ->var ->name !== 'this '
37483744 ) {
37493745 continue ;
37503746 }
37513747
3752- $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3753- if ($ propertyReflection === null ) {
3754- continue ;
3755- }
3748+ while ($ expr instanceof PropertyFetch) {
3749+ if ($ expr ->var instanceof Variable) {
3750+ if (
3751+ ! $ expr ->name instanceof Node \Identifier
3752+ || !is_string ($ expr ->var ->name )
3753+ || $ expr ->var ->name !== 'this '
3754+ ) {
3755+ continue 2 ;
3756+ }
3757+ } elseif (!$ expr ->var instanceof PropertyFetch) {
3758+ continue 2 ;
3759+ }
37563760
3757- $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3758- if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3759- continue ;
3761+ $ propertyReflection = $ this ->propertyReflectionFinder ->findPropertyReflectionFromNode ($ expr , $ this );
3762+ if ($ propertyReflection === null ) {
3763+ continue 2 ;
3764+ }
3765+
3766+ $ nativePropertyReflection = $ propertyReflection ->getNativeReflection ();
3767+ if ($ nativePropertyReflection === null || !$ nativePropertyReflection ->isReadOnly ()) {
3768+ continue 2 ;
3769+ }
3770+
3771+ $ expr = $ expr ->var ;
37603772 }
37613773
37623774 $ 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