-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resolving
self
and static
in @phpstan-closure-this
from tra…
…it stub file
- Loading branch information
1 parent
9ff5aaf
commit 9340249
Showing
10 changed files
with
211 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Analyser; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
|
||
class Bug11009Test extends TypeInferenceTestCase | ||
{ | ||
|
||
public function dataFileAsserts(): iterable | ||
{ | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-11009.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
* @param mixed ...$args | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args, | ||
): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/../../../conf/bleedingEdge.neon', | ||
__DIR__ . '/bug-11009.neon', | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
parameters: | ||
stubFiles: | ||
- data/bug-11009.stub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Bug11009; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
trait A | ||
{ | ||
public static function callbackStatic(callable $cb): void | ||
{ | ||
} | ||
|
||
public static function callbackSelf(callable $cb): void | ||
{ | ||
} | ||
|
||
public function returnStatic() | ||
{ | ||
return $this; | ||
} | ||
|
||
public function returnSelf() | ||
{ | ||
return new self; | ||
} | ||
} | ||
|
||
class B | ||
{ | ||
use A; | ||
} | ||
|
||
function (): void { | ||
B::callbackStatic(function (): void { | ||
assertType(B::class, $this); | ||
}); | ||
|
||
B::callbackSelf(function (): void { | ||
assertType(B::class, $this); | ||
}); | ||
|
||
$b = new B(); | ||
assertType(B::class, $b->returnStatic()); | ||
assertType(B::class, $b->returnSelf()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Bug11009; | ||
|
||
trait A { | ||
/** | ||
* @param-closure-this static $cb | ||
*/ | ||
public static function callbackStatic(callable $cb): void {} | ||
|
||
/** | ||
* @param-closure-this self $cb | ||
*/ | ||
public static function callbackSelf(callable $cb): void {} | ||
|
||
/** @return static */ | ||
public function returnStatic() {} | ||
|
||
/** @return self */ | ||
public function returnSelf() {} | ||
} |