File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 5050use PHPStan \Node \Printer \ExprPrinter ;
5151use PHPStan \Node \PropertyAssignNode ;
5252use PHPStan \Parser \ArrayMapArgVisitor ;
53+ use PHPStan \Parser \ImmediatelyInvokedClosureVisitor ;
5354use PHPStan \Parser \NewAssignedToPropertyVisitor ;
5455use PHPStan \Parser \Parser ;
5556use PHPStan \Php \PhpVersion ;
@@ -3714,6 +3715,7 @@ private function enterAnonymousFunctionWithoutReflection(
37143715 && $ expr ->var instanceof Variable
37153716 && is_string ($ expr ->var ->name )
37163717 && $ expr ->var ->name === 'this '
3718+ && $ closure ->getAttribute (ImmediatelyInvokedClosureVisitor::ATTRIBUTE_NAME ) === true
37173719 && !$ closure ->static
37183720 && $ this ->hasVariableType ('this ' )->yes ()
37193721 && $ this ->phpVersion ->supportsReadOnlyProperties ()
Original file line number Diff line number Diff line change @@ -29,10 +29,17 @@ public function bar(): void
2929 return ;
3030 }
3131
32- $ test = function () {
32+ ( function () {
3333 assertType (Foo::class, $ this ->foo );
3434 assertType (Foo::class.'|null ' , $ this ->writableFoo );
3535
36+ echo $ this ->foo ->value ;
37+ })();
38+
39+ $ test = function () {
40+ assertType (Foo::class.'|null ' , $ this ->foo );
41+ assertType (Foo::class.'|null ' , $ this ->writableFoo );
42+
3643 echo $ this ->foo ->value ;
3744 };
3845
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public function bar(): void
3232 assertType ('non-empty-string ' , $ this ->foo ->value );
3333
3434 $ test = function () {
35- assertType (Foo::class, $ this ->foo );
35+ assertType (Foo::class. ' |null ' , $ this ->foo );
3636 assertType ('string ' , $ this ->foo ->value );
3737 };
3838
You can’t perform that action at this time.
0 commit comments